ava.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security polic
Android P http网络请求的问题
Google表示,为保证用户数据和设备的安全,针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输,需要使用下一代(Transport Layer Security)传输层安全协议,而 Android Nougat 和 Oreo 则不受影响。
因此在Android P 使用HttpUrlConnection进行http请求会出现以下异常
java.io.IOException: Cleartext HTTP traffic to **** not permitted
1
使用OKHttp请求则出现
java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security policy
1
在Android P系统的设备上,如果应用使用的是非加密的明文流量的http网络请求,则会导致该应用无法进行网络请求,https则不会受影响,同样地,如果应用嵌套了webview,webview也只能使用https请求。
有人认为 Android P 上所有的 App 都需要使用 TLS 加密会降低上网体验,事实上这是一种误解,至于 App 对于少数旧服务器的连接如果非要使用明码传输,开发者需要更改 App 的网络安全配置以允许此类连接。
有以下三种解决方案:
1、APP改用https请求
2、targetSdkVersion 降到27以下
3、在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml 文件(名字自定) ,内容如下,大概意思就是允许开启http请求
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
然后在APP的AndroidManifest.xml文件下的application标签增加以下属性
<application
...
android:networkSecurityConfig="@xml/network_security_config"
...
/>
相关参考链接:
https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html
https://android-developers.googleblog.com/2018/04/dns-over-tls-support-in-android-p.html
ava.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security polic相关推荐
- java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security polic
转载仅供本人存档及后续研究使用,请尊重原创. 转载自:https://blog.csdn.net/yonbor605/article/details/82223882 Android P http网络 ...
- CLEARTEXT communication to v.juhe.cn not permitted by network security polic
在AndroidManifest.xml的application中添加属性: android:usesCleartextTraffic="true" 即可.
- CLEARTEXT communication to xxx not permitted by network security policy
2019独角兽企业重金招聘Python工程师标准>>> Android P http网络请求不通,报出异常:java.net.UnknownServiceException: CLE ...
- 【Android】【网络请求】解决cleartext communication not permitted问题
androidSDK从9.0开始,强制要求使用https协议 如果使用了9.0以上的SDK,但没有使用https协议,就会报以下错误: CLEARTEXT communication not perm ...
- java.net.UnknownServiceException: CLEARTEXT communication to wanandroid.com not permitted by network
java.net.UnknownServiceException: CLEARTEXT communication to wanandroid.com not permitted by network ...
- java.net.UnknownServiceException: CLEARTEXT communication to leshibaojishi.qiweibang.com not permitt
java.net.UnknownServiceException: CLEARTEXT communication to leshibaojishi.qiweibang.com not permitt ...
- Android 9.0以上联网报错:CLEARTEXT communication to xxx.xxx.xxx.xx not permitted by network security policy
Google为了保证用户数据和设备安全,针对Android 系统(Android P) 的应用程序,将要求默认使用加密连接.Android P 将禁止 App 使用所有未加密的连接,因此运行 Andr ...
- CLEARTEXT communication to “ “ not permitted by network security policy处理办法
ok http3 + retrofit 网络请求,在Android9.0手机上请求失败,报错:CLEARTEXT communication to " " not permitte ...
- 网络请求失败CLEARTEXT communication to “ “ not permitted by network security policy
ok http3 + retrofit 网络请求,在Android9.0手机上请求失败,报错:CLEARTEXT communication to " " not permitte ...
最新文章
- 网络之NSURLSession
- 20155317《网络对抗》Exp4 恶意代码分析
- (一:NIO系列)JAVA NIO 简介
- golang 正则 校验 字符串
- MFC文件操作大全,打开,保存,复制,删除,查找等
- 自动化测试框架搭建-配置-1
- Java项目 常用包的命名及理解【dao包、domain包、service包、utils包、web包、impl包】
- ubuntu 14.04 安装Java JDK
- tomcat不重启java文件自动编译
- CSS3的radial-gradient(径向渐变)
- Sigar - no sigar-amd64-winnt.dll in java.library.path
- sql server 数组_如何在SQL Server中实现类似数组的功能
- 从宏杉合作伙伴大会看本土存储厂商的“逆袭”
- 【原】小软件开发心得(一)——需求、开发
- 【微信小程序】入门第一篇 注册账号
- mysql辅助索引非叶子节点_Mysql的聚集索引与辅助索引
- PermissionError: [Errno 13] Permission denied: ‘C:\\Users\\langxu\\AppData\\Local\\Temp
- CSS文字超出部分用省略号代替,js鼠标悬停时显示全部文本
- 字符串分段组合python123_boost python分段fau
- cocos2d 高仿doodle jump 无源代码