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

Android版本28使用http请求报错not permitted by network security policy的更多相关文章

  1. Android版本28使用http请求

    Android版本28使用http请求报错not permitted by network security policy android模拟器调试登录的时候报错 CLEARTEXT communic ...

  2. 安卓工作室 android studio 汉化后,报错。 设置界面打不开。Can't find resource for bundle java.util.PropertyResourceBundle, key emmet.bem.class.name.element.separator.label

    安卓工作室 android studio 汉化后,报错. 设置界面打不开. Android studio has been sinified and reported wrong.The setup ...

  3. mysql 5.7.28 中GROUP BY报错问题 SELECT list is not in GROUP BY clause and contains no

    ----mysql 5.7.28 中GROUP BY报错问题 SELECT list is not in GROUP BY clause and contains no------ 解决方案: sel ...

  4. Android Studio使用org.apache.http报错

    Android Studio使用org.apache.http报错需要加上这句话:useLibrary 'org.apache.http.legacy'

  5. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  6. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  7. nuget包管理nuget服务器发布包时出现请求报错 406 (Not Acceptable)

    在window服务器上部署nuget服务器时,发布包时出现请求报错 406 (Not Acceptable) 验证用户名.密码正确的情况下,还是出现上面错误.后面跟踪服务器日志,发现window\te ...

  8. git https 请求报错 504

    git https 请求报错 504 原因可能是因为设置了代理,ubuntu/deepin 系统可以检查 /etc/profile ~/.bashrc 内有没有设置 https 的代理. 有的话,去掉 ...

  9. JS请求报错:Unexpected token T in JSON at position 0

    <?php /* 最近做一个ajax validate表单验证提交的代码,在ajax提交的时候 JS请求报错:Unexpected token T in JSON at position 0 描 ...

随机推荐

  1. [pytorch修改]dataloader.py 实现darknet中的subdivision功能

    dataloader.py import random import torch import torch.multiprocessing as multiprocessing from torch. ...

  2. 【jvisualvm远程监控配置】

    第一步:首先通过hostname -i  和ifconfig命令,查看一下IP地址是否一致 如果不一致,修改hosts的IP地址:vi /etc/hosts    把ip地址和ifconfig的地址修 ...

  3. linux shell中如何往所有行尾添加内容

    答: sed -i 's/$/yes/' jello.txt 这句话的意思就是在jello.txt文件的所有行尾都添加相同的内容yes,如jello.txt原来的内容为: no jello hello ...

  4. Learning-Python【13】:迭代器和生成器

    一.什么是迭代器 迭代指的是一个重复的过程,每一次重复都是基于上一次的结果而来的 # 这里的循环也是一个迭代,每次基于上一次的结果而取值 li = 'hello' i = 0 while i < ...

  5. read_csv 的 names 和 index_col 参数作用

  6. LRU的实现

    https://blog.csdn.net/elricboa/article/details/78847305 未看懂https://zhuanlan.zhihu.com/p/34133067

  7. 对啊英语音标---二、ghywr这些辅音怎么发音

    对啊英语音标---二.ghywr这些辅音怎么发音 一.总结 一句话总结:对比法,和汉语拼音做对比 对比法,和汉语拼音做对比 1.清辅音和浊辅音的区别是什么? 清辅音-[不需要声带震动]就能发出的音节: ...

  8. IDEA spirng boot @Autowired注解 mapper出现红色下划线解决方法

    如图所示,解决方法为: 把勾去掉即可.

  9. 不正常退出vim产生swp文件的解决方法

    vi -r README.txt恢复文件,这样上次意外退出没有保存的修改,就会覆盖文件. vi -r查看生成的交换文件 rm .README.txt.swp删除交换文件 搞定!下次打开文件就可以正常编 ...

  10. 7.5 GRASP原则五:高内聚 High Cohesion

    GRASP原则五:高内聚 High Cohesion  How to keep objects focused, understandable and manageable, and as a si ...