SSL错误阻止网站登录混乱

干草,

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

当前代码:

  @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和Swift编写自己的程序包或自定义WebView更好的方法了?

回答:

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

public void onReceivedSslError (WebView view, SslErrorHandler handler,

SslError error) 用简单的实现覆盖handler.proceed()

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

dependencies:

flutter_webview_plugin:

path: ../flutter_webview_plugin

以上是 SSL错误阻止网站登录混乱 的全部内容, 来源链接: utcz.com/qa/415496.html

回到顶部