fix: 代理导致的网络异常 issues #242
This commit is contained in:
@ -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) {
|
// return 'PROXY host:port';
|
||||||
print('🌹:$systemProxyHost');
|
return 'PROXY $systemProxyHost:$systemProxyPort';
|
||||||
print('🌹:$systemProxyPort');
|
|
||||||
|
|
||||||
// return 'PROXY host:port';
|
|
||||||
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());
|
||||||
|
|||||||
Reference in New Issue
Block a user