zoukankan      html  css  js  c++  java
  • Android版本28使用http请求报错not permitted by network security policy

    Android版本28使用http请求报错not permitted by network security policy

    android模拟器调试登录的时候报错 CLEARTEXT communication to to 52.76.xx.xxx not permitted by network security policy

    2018-10-17 20:42:09.532 18048-18048/com.aax.exchange E/ProgressObserver____: onError:
    java.net.UnknownServiceException: CLEARTEXT communication to 52.76.xx.xxx not permitted by network security policy

    问题: 由于 Android P(版本27以上) 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。
    如果当前应用的请求是 htttp 请求,而非 https ,这样就会导系统禁止当前应用进行该请求

    推荐的做法是服务器和本地应用都改用 https ,测试时为了方便使用http,上线时应该都会用https才比较安全。

    解决办法:1.在 res 下新建一个 xml 目录,然后创建一个名为:network_security_config.xml 文件 ,该文件内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
    <base-config cleartextTrafficPermitted="true" />
    </network-security-config>

    在 AndroidManifest.xml application增加配置android:networkSecurityConfig="@xml/network_security_config"

    后不报错了

    2:服务器和本地应用都改用 https (推荐)

    3:targetSdkVersion 降级回到 27

  • 相关阅读:
    CodeVs 1295 N皇后问题
    POJ 3349 Snowflake Snow Snowflakes
    链表API
    Hash API
    CodeVS 1220 数字三角形
    CodeVS 1045 回文数
    CodeVS 1058 合唱队形(DP--最长子序列问题)
    CodeVS 1018 单词接龙(DFS)
    关于图覆盖问题习题BY石家名
    软件测试作业(二)
  • 原文地址:https://www.cnblogs.com/zdz8207/p/Android-28-http-https.html
Copyright © 2011-2022 走看看