我正在尝试使用WebView构建应用程序,该应用程序加载页面的代理。我需要以编程方式更改代理(要设置IP,端口,用户名和密码)。
我有一个想法要使用 webViewScaffold (Flutter_webview_plugin: ^0.3.0 2) ,并在全球范围内覆盖 httpclclient ,/p>
class CustomHttp extends HttpOverrides{
@override
HttpClient createHttpClient(SecurityContext securityContext){
var client = new HttpClient();;
client.findProxy = (Uri uri) {
return 'PROXY XX.XX.XX.XX:{PORT};';
};
client.authenticate = (uri, scheme, realm) {
client.addCredentials(uri, realm, new HttpClientBasicCredentials('username', 'password'));
};
return client;
}
}
但是没有运气。看起来WebViewScaffold不使用全局httpclient。
有人知道我该怎么做?
可以通过在Flutter HTTP请求中设置所有请求的默认标头来完成。
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext context) {
return new MyHttpClient(super.createHttpClient(context));
}
}
void main() {
HttpOverrides.global = new MyHttpOverrides();
runApp(MyApp());
}
您可以在httpclient类中指定您的代理设置。