flutter使用Charles代理爬虫
由于flutter的http请求代理不走系统,所以只能在代码中设置代理ip:
class MyHttpOverrides extends HttpOverrides { bool _badCertificateCallback(X509Certificate cert, String host, int port) { return true; } @override HttpClient createHttpClient(SecurityContext? context) { return super.createHttpClient(context) ..badCertificateCallback = _badCertificateCallback ..findProxy = (uri) { return 'PROXY 192.168.1.193:8888;DIRECT;';//192.168.1.193:8888是代理ip端口
}
;
}
}
在启动时设置httpoverride
HttpOverrides.global = MyHttpOverrides();
修改Charles的ssl代理设置,Proxy->SSL Proxying Settings -> SSL Proxying->Include,添加要需要爬取的域名。
转载请注明出处,from 博客园HemJohn