【问题标题】:Flutter WebView with proxyFlutter WebView 与代理
【发布时间】:2019-07-12 19:01:24
【问题描述】:

我正在尝试使用加载代理页面的 webview 构建应用程序。我需要以编程方式更改代理(设置 ip、端口、用户名和密码)。

我想使用 WebviewScaffold (flutter_webview_plugin: ^0.3.0+2) 并像这样全局覆盖 HttpClient

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。

有人知道我该怎么做吗?

【问题讨论】:

    标签: android ios webview dart flutter


    【解决方案1】:

    可以通过设置flutter HTTP请求中所有请求的默认header来实现。

    class MyHttpOverrides extends HttpOverrides {
      @override
      HttpClient createHttpClient(SecurityContext context) {
        return new MyHttpClient(super.createHttpClient(context));
      }
    }
    
    void main() {
      HttpOverrides.global = new MyHttpOverrides();
      runApp(MyApp());
    }
    

    您可以在 HttpClient 类中指定您的代理设置。

    【讨论】:

    • 我试过这种方式,但它不起作用。 webview 仍然没有使用代理。
    • 不幸的是,我知道,您无法为 Android 上的任何 webview 设置代理。 :-(
    猜你喜欢
    • 2021-06-28
    • 2012-09-25
    • 1970-01-01
    • 2019-12-14
    • 2011-05-28
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多