使用音频包(本地主机)连接超时



我使用dio包在我的朋友开发的本地api上使用post方法,首先我得到了一个套接字异常,但我解决了它用我当前的ip替换127.0.0.1并运行php artisan serve --host 192.168.1.105,之后我得到了连接超时,看起来像是一个常见的错误,但我想也许我的情况不同,这是我的dio类:

import 'package:dio/dio.dart';
class DioHelper {
static Dio? dio;
static init() {
dio = Dio(BaseOptions(
baseUrl: "http://192.168.1.105:8000/api/",
responseType: ResponseType.json,
receiveTimeout: 30000,
connectTimeout: 500000,
followRedirects: false,
receiveDataWhenStatusError: true,
));
}

static Future<Response> post(
{required String url,
Map<String, dynamic>? query,
Map<String, dynamic>? body}) async {
return await dio!.post(url, queryParameters: query, data: body);
}
}

正如你所看到的,无论我连接超时多长时间,我仍然得到相同的错误,请提供一些解释这个错误和可能的解决方案。

尝试运行php artisan serve——host=0.0.0.0,然后如果您正在使用模拟器,使用10.0.2.2作为您的基础url,如果您正在使用真实设备,则使用您的IP地址。确保两个设备连接在同一个端口