SSL错误阻止网站登录混乱 [英] SSL error prevents website login in flutter

查看:84
本文介绍了SSL错误阻止网站登录混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为Xamarin的替代品,我试图创建一个具有相同功能的应用程序。
但是webview插件/软件包无法使用自签名的ssl证书。
在Xamarin中,有一种方法可以处理ssl错误,而
仍然可以加载网站。

as a replacement for Xamarin I tried to create a app with the same functions in flutter. But the webview plugin/package doens't work with the self signed ssl certificate. In Xamarin there was a way to handle the ssl errors and still get the website loaded.

当前代码:

  @override
  void initState() {
    super.initState();
    final flutterWebviewPlugin = new FlutterWebviewPlugin();
    flutterWebviewPlugin.onHttpError.skip(1000);
    flutterWebviewPlugin.launch("https url to website", hidden: true,
        allowFileURLs: true,
        appCacheEnabled: true,
        withJavascript: true,
        withLocalStorage: true,
        withZoom: true);

flutterWebviewPlugin.onHttpError.skip(1000);
flutterWebviewPlugin.onStateChanged((state) async)
{
  flutterWebviewPlugin.evalJavascript(
      "document.getElementById(\"name\").innerText = \"username\"");
  flutterWebviewPlugin.evalJavascript(
      "document.getElementById(\"password\").innerText = \"pw\"");
  flutterWebviewPlugin.evalJavascript(
      "document.getElementById(\"loginbutton\").invokeMember(\"click\")");
  var test = flutterWebviewPlugin.evalJavascript(
      "document.getElementById(\"errorbox\").innerText");
};
flutterWebviewPlugin.dispose();
flutterWebviewPlugin.close();

错误:

Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

有没有比在Java中更快地编写自己的程序包或自定义WebView更好的方法了?

Is there a better way then writing an own package or an custom webview in java and swift?

推荐答案

在Android上,您可以修改插件。将副本克隆到本地计算机上,并向 flutter_webview_plugin / android / src / main / java / com / flutter_webview_plugin / BrowserClient.java

On Android you could modify the plugin. Clone a copy to your local machine and add an additional override to flutter_webview_plugin/android/src/main/java/com/flutter_webview_plugin/BrowserClient.java

重写 public void onReceivedSslError(WebView视图,
SslErrorHandler处理程序,
SslError错误)

,带有实现只是做 handler.proceed()

假设您的项目位于 / projects中/ myproject ,然后将插件克隆到 / projects / flutter_webview_plugin 中。在 / projects / flutter_webview_plugin / android / src /.../ BrowserClient.java 中进行更改。然后使用(替换flutter_webview_plugin的现有条目)更新项目的 pubspec.yaml

Let's say your project is in /projects/myproject and you cloned the plugin into /projects/flutter_webview_plugin. Make the change in /projects/flutter_webview_plugin/android/src/.../BrowserClient.java. Then update the pubspec.yaml of your project with (replaces the existing entry for flutter_webview_plugin):

dependencies:
  flutter_webview_plugin:
    path: ../flutter_webview_plugin

这篇关于SSL错误阻止网站登录混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆