我遇到了这个问题,并在flutter_webview_pugin和webview_flutter.的帮助下解决了这个问题,但是我花了一些时间才找到将代码放在哪里的方法,因为在这和webview_flutter.之间,代码有点不同。因此,本教程将演示如何在webview_flutter上MacOS上实现此方法(仅在windows上的文件可能有所不同)。
1-将此文件夹/Volumes/.../Flutter/SDK/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.10+4复制到从项目的根向上一步的地方,例如。
如果这是您的项目:/Volumes/Depo/MyProject/,那么将插件文件夹放在这里是很方便的:/Volumes/Depo/edited/
2- 然后打开这个文件
然后加上这一行
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}转到internalCreateWebViewClient函数。你做完之后应该是这样的
private WebViewClient internalCreateWebViewClient() {
return new WebViewClient() {
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return FlutterWebViewClient.this.shouldOverrideUrlLoading(view, request);
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onPageFinished(WebView view, String url) {
FlutterWebViewClient.this.onPageFinished(view, url);
}
};
}3-加上这些进口品
import android.net.http.SslError;
import android.webkit.SslErrorHandler;由于此方法绕过SSL,因此不建议用于生产。
即使服务器的SSL证书有效,也会发生此问题。由于有效的SSL不能保证客户端通过该域到达的每个服务最终都使用相同的原点(在我的例子中),所以我试图连接到服务器,使用RTSP来流安全凸轮,但是在第一个请求上是"101交换协议“,在没有有效SSL的不同端口实现。
发布于 2019-11-29 21:49:42
你可以使用我的插件inappwebview。它有很多事件,包括管理SSL错误的事件和SSL客户端证书请求:
onReceivedServerTrustAuthRequest:当WebView需要执行服务器信任身份验证(证书验证)时触发的事件。这是使用Android上的onReceivedSslError事件实现的。onReceivedClientCertRequest:通知主机应用程序处理SSL证书请求。因此,在您的例子中,您只需要使用onReceivedServerTrustAuthRequest事件并返回简单的ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED);
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: InAppWebViewPage()
);
}
}
class InAppWebViewPage extends StatefulWidget {
@override
_InAppWebViewPageState createState() => new _InAppWebViewPageState();
}
class _InAppWebViewPageState extends State<InAppWebViewPage> {
InAppWebViewController webView;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("InAppWebView")
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://myUrl",
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions(
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) {
},
onReceivedServerTrustAuthRequest: (InAppWebViewController controller, ServerTrustChallenge challenge) async {
return ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED);
},
),
),
),
]))
);
}
}"https://myUrl"是你的网址。
https://stackoverflow.com/questions/57253385
复制相似问题