fix: 代理导致的网络异常 issues #242

This commit is contained in:
guozhigq
2023-11-14 00:06:16 +08:00
parent 98c2a4243d
commit bbfb3175fe

View File

@ -115,30 +115,24 @@ class Request {
idleTimeout: const Duration(milliseconds: 10000), idleTimeout: const Duration(milliseconds: 10000),
onClientCreate: (_, config) => config.onBadCertificate = (_) => true, onClientCreate: (_, config) => config.onBadCertificate = (_) => true,
), ),
) );
/// 设置代理 /// 设置代理
..httpClientAdapter = IOHttpClientAdapter( if (enableSystemProxy) {
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () { createHttpClient: () {
final client = HttpClient(); final client = HttpClient();
// Config the client. // Config the client.
client.findProxy = (uri) { client.findProxy = (uri) {
if (enableSystemProxy) {
print('🌹:$systemProxyHost');
print('🌹:$systemProxyPort');
// return 'PROXY host:port'; // return 'PROXY host:port';
return 'PROXY $systemProxyHost:$systemProxyPort'; return 'PROXY $systemProxyHost:$systemProxyPort';
} else {
// 不设置代理
return 'DIRECT';
}
}; };
client.badCertificateCallback = client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true; (X509Certificate cert, String host, int port) => true;
return client; return client;
}, },
); );
}
//添加拦截器 //添加拦截器
dio.interceptors.add(ApiInterceptor()); dio.interceptors.add(ApiInterceptor());