手机和电脑连上同一个wifi,并且手机wifi使用代理,代理地址为电脑的ip和proxyman设置的监听端口
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'dart:io';
class ProxyUtil {
static String proxyIP = "";
static String proxyPort = "9090";
static Dio useProxy(Dio dio) {
if (proxyIP == "") return dio;
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
final client = HttpClient();
client.findProxy = (uri) {
// Proxy all request to localhost:8888.
// Be aware, the proxy should went through you running device,
// not the host platform.
return 'PROXY $proxyIP:$proxyPort';
};
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
return client;
},
);
return dio;
}
}
使用方式
Dio dio = Dio();
ProxyUtil.useProxy(dio);
proxyIP
为电脑ip