flutter_inappwebview请求http报错This request has been blocked


flutter_inappwebview 请求网页的时候 内部ajax 访问http 会失败,提示如下:
Mixed Content: The page at 'https://<page url>' was loaded over HTTPS, but requested an insecure video 'http://<video url>.mp4'. This request has been blocked; the content must be served over HTTPS.
在配置选项中增加一条
示例代码:
child: InAppWebView( initialUrlRequest: URLRequest(url: Uri.parse("https://yourwebsite.com")), initialOptions: InAppWebViewGroupOptions( android: AndroidInAppWebViewOptions( mixedContentMode: AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW ) ), )
我首先使用了一下方式,结果报错依旧,这里也贴出来做个参考。
项目文件夹\android\app\src\main\AndroidManifest.xml
application 中新增两行
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
新增文件:
项目文件夹\android\app\src\main\res\xml\network_security_config.xml
内容:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>

发表评论

您的电子邮箱地址不会被公开。