Webview 未在 android 中加载 url
Webview not loading url in android
我有这个代码。
@SuppressLint("SetJavaScriptEnabled")
@Composable
fun WebPageScreen(urlToRender: String) {
AndroidView(factory = {
WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
webViewClient = WebViewClient()
loadUrl("https:....") //Url to be loaded
}
}, update = {
it.loadUrl("https:...") //Url to be loaded
})
}
我正在尝试加载这个 url
当我加载此页面时,它正在重定向但显示错误这是什么问题以及如何解决这个问题?
创建这个文件
res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">URL</domain>
</domain-config>
</network-security-config>
在应用程序内的清单中添加此行
android:networkSecurityConfig="@xml/network_security_config"
或
您可以在清单中使用这一行
android:usesCleartextTraffic="true"
如果您的网站尚未使用 SSL,您可以使用 certbot 免费 SSL
Web 视图不适用于特定的 url,因为该网站的授权人已经以这种方式对其进行了保护。要在 webview 中访问 url,我们需要从权威机构获取客户端证书。
我有这个代码。
@SuppressLint("SetJavaScriptEnabled")
@Composable
fun WebPageScreen(urlToRender: String) {
AndroidView(factory = {
WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
webViewClient = WebViewClient()
loadUrl("https:....") //Url to be loaded
}
}, update = {
it.loadUrl("https:...") //Url to be loaded
})
}
我正在尝试加载这个 url
当我加载此页面时,它正在重定向但显示错误这是什么问题以及如何解决这个问题?
创建这个文件
res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">URL</domain>
</domain-config>
</network-security-config>
在应用程序内的清单中添加此行
android:networkSecurityConfig="@xml/network_security_config"
或
您可以在清单中使用这一行
android:usesCleartextTraffic="true"
如果您的网站尚未使用 SSL,您可以使用 certbot 免费 SSL
Web 视图不适用于特定的 url,因为该网站的授权人已经以这种方式对其进行了保护。要在 webview 中访问 url,我们需要从权威机构获取客户端证书。