Flutter webview 是否还需要 SSL 证书?

Is a SSL certificate still needed in a Flutter webview?

我们目前有一个 Angular 为在线订购实用程序创建的网络应用程序。 但是我们想用它创建一个原生应用程序,我们想使用 Flutter。

起初,虽然我们只是想使用网络视图通过那里显示现有的 Angular 应用程序。

问题是,我们想这样做是因为我们还想摆脱通过 phone.

访问应用程序所需的 SSL 证书

webview 还需要 SSL 证书吗?

我想是因为它仍然像访问网页一样,但我想确定一下。

webview_flutter package has no option to disable SSL checks and ignore SSL errors. It is an official Flutter plugin and they don't want to provide an ability to make untrusted connections with https. Here is related issue github。

但是,您可以使用提供此类功能的非官方 webview 插件。例如。 flutter_webview_plugin:

final flutterWebviewPlugin = new FlutterWebviewPlugin();

flutterWebviewPlugin.launch(
    'your-url.com',
    ignoreSSLErrors: true,
);

webview_flutter 插件没有任何忽略 SSL 错误的选项。 相反,使用我的 flutter_inappwebview 插件,忽略 SSL 错误非常简单,就像您通常在 Android 上所做的那样,即使用 onReceivedServerTrustAuthRequest 事件和 returning ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED); 用于指定请求或所有请求。

一个使用最新版本 5.0.5+3 and https://badssl.com/ (that is a site for testing clients against bad SSL configs, see https://github.com/chromium/badssl.com) 的简单示例是:

child: InAppWebView(
  initialUrlRequest: URLRequest(
      url: Uri.parse("https://self-signed.badssl.com/")
  ),
  onReceivedServerTrustAuthRequest: (controller, challenge) async {
    print(challenge);
    return ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED);
  },
),

其中 challenge 参数提供有关挑战的所有信息,例如主机、协议、领域等。

此外,在 Android,当您 return 采取行动(PROCEEDCANCEL)时,此决定由 Android 保存本身,因此下次您转到相同的 URL 时,将不会触发 onReceivedServerTrustAuthRequest 事件。 在这种情况下,您可以使用 controller.android.clearSslPreferences() 方法清除 Android SSL 首选项。