【问题标题】:ERR_CLEARTEXT_NOT_PERMITTED on Android 9, with domain cleartext permittedAndroid 9 上的 ERR_CLEARTEXT_NOT_PERMITTED,允许域明文
【发布时间】:2021-01-26 00:04:39
【问题描述】:

在 Android 10 设备上,我在我的 http 服务器上的 webview 中收到 ERR_CLEARTEXT_NOT_PERMITTED 错误,但仅在某些页面上,即使我使用 network_security_config 来允许域。我只能通过使用打开所有域来解决该错误。如何解决此问题,以便只允许我的域,而不收到错误,但不使用?

Logcat:

07:54:09.004 com.myserver.myapp D/myapp: Webview.onPageStarted called on http://myserver.com/myapp/index.php?view=discrete
07:54:09.232 com.myserver.myapp I/myapp: onPageFinished called.
07:54:15.938 com.myserver.myapp D/myapp: Webview.onPageStarted called on http://myserver.com/myapp/index.php?view=about
07:54:15.958 com.myserver.myapp I/myapp: onReceivedError called.
07:54:15.958 com.myserver.myapp I/myapp: Web Load Error:net::ERR_CLEARTEXT_NOT_PERMITTED
07:54:16.012 com.myserver.myapp I/myapp: onPageFinished called.

网络安全配置 xml:

<network-security-config>
<domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">localhost</domain>
    <domain includeSubdomains="true">myserver.com</domain>
</domain-config>
    <!-- Want to delete this for better security--> 
    <base-config cleartextTrafficPermitted="true"/>
</network-security-config>

【问题讨论】:

  • 构建是android 9(SDK 28),设备是android 10
  • 发帖AndroidManifest.xml
  • 这能回答你的问题吗? Android 8: Cleartext HTTP traffic not permitted
  • 如果您的页面包含来自其他网站的 JavaScript、图片等,则可能会触发此错误。你确定你的所有页面元素都被你的&lt;domain&gt;元素覆盖了吗?

标签: android security cleartext


【解决方案1】:

根本原因是提供第三方广告内容 (Google Ads) 的 javascript 没有使用 https。

添加代码到 onReceivedError 以记录导致问题的 URL...

public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            Log.i(TAG, "onReceivedError called for URL "+ request.getUrl().toString());
}


  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    • 2017-11-06
    • 2023-03-19
    相关资源
    最近更新 更多