flutter dio 抓包
1、第一种
写一个页面,输入ip地址和端口号,传给dio设置里
(_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
client.idleTimeout = const Duration(seconds: 5);
client.findProxy = (uri) {
return "PROXY ${ip地址}:${端口号}";
};
//代理工具会提供一个抓包的自签名证书,会通不过证书校验,所以我们禁用证书校验
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
return null;
}
2、第二种
引入http_proxy: ^1.2.0第三方库,可获取代理信息
HttpProxy proxy = await HttpProxy.createHttpProxy();
debugPrint("PROXY=${proxy.host}");
if (proxy.host != null) {
(_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
client.idleTimeout = const Duration(seconds: 5);
client.findProxy = (uri) {
return "PROXY ${proxy.host}:${proxy.port}";
};
//代理工具会提供一个抓包的自签名证书,会通不过证书校验,所以我们禁用证书校验
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
return null;
};
}
网友评论