flutter webview 加载不出html 其他页面都可以,https请求证书信任

关于webview加载不出html,反而百度等一些html能加载出来。应该是证书问题。

1,第一步:

flutter webview 加载不出html 其他页面都可以,https请求证书信任

android:usesCleartextTraffic="true" 加上这行

第二步:

flutter webview 加载不出html 其他页面都可以,https请求证书信任

android:networkSecurityConfig="@xml/network_security_config"

加上这行

第三步:

flutter webview 加载不出html 其他页面都可以,https请求证书信任

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <!-- 信任系统预装 CA 证书 -->
            <certificates src="system" />
            <!-- 信任用户添加的 CA 证书,Charles 和 Fiddler 抓包工具安装的证书属于此类 -->
            <certificates src="user" />
        </trust-anchors>
    </base-config>
</network-security-config>

加上这个文件,内容如上,可以只写一个system,不用那个user。

 

 

2,对于一些https请求还要有请求头。用

WidgetsBinding.instance.addPostFrameCallback((_) {
  Map<String, String> headers = {};
  headers.addAll({"sessionToken": "Android"});
  _controller?.loadUrl(widget.initialUrl, headers: headers);
});

再配置一下UserAgent就行了。