java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted
java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted
Android9.0 默认是禁止所有的http
请求的,需要在代码中设置如下代码才可以正常进行网络请求: android:usesCleartextTraffic="true"。如图
- <application
- android:name="xxxx.xxxx.xxx.xxx"
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppBaseTheme"
- android:usesCleartextTraffic="true">
Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法
前言:为保证用户数据和设备的安全,Google针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输,需要使用下一代(Transport Layer Security)传输层安全协议,而 Android Nougat 和 Oreo 则不受影响。
因此在Android P 使用HttpUrlConnection进行http请求会出现以下异常
W/System.err: java.io.IOException: Cleartext HTTP traffic to **** not permitted
使用OKHttp请求则出现
java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security policy
在Android P系统的设备上,如果应用使用的是非加密的明文流量的http网络请求,则会导致该应用无法进行网络请求,https则不会受影响,同样地,如果应用嵌套了webview,webview也只能使用https请求。
针对这个问题,有以下三种解决方法:
(1)APP改用https请求
(2)targetSdkVersion 降到27以下
(3)更改网络安全配置
前面两个方法容易理解和实现,具体说说第三种方法,更改网络安全配置。
1.在res文件夹下创建一个xml文件夹,然后创建一个network_security_config.xml文件,文件内容如下:
- <?xml version="1.0" encoding="utf-8"?>
- <network-security-config>
- <base-config cleartextTrafficPermitted="true" />
- </network-security-config>
2.接着,在AndroidManifest.xml文件下的application标签增加以下属性:
- <application
- ...
- android:networkSecurityConfig="@xml/network_security_config"
- ...
- />
完成,这个时候App就可以访问网络了。
java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted的更多相关文章
- Caused by : java.io.IOException: Cleartext HTTP traffic to 《“url”》 not permitted
一.问题原因: 根本原因是从Android9.0开始,出于完全因素考虑,默认不再支持http网络请求,需要使用 https. 二.解决方案: 解决的基本思路是:对指定的网址进行过滤,强制允许指定网址继 ...
- hadoop报错:java.io.IOException(java.net.ConnectException: Call From xxx/xxx to xxx:10020 failed on connection exception: java.net.ConnectException: 拒绝连接
任务一直报错 现象比较奇怪,部分任务可以正常跑,部分问题报错 报错信息如下: Ended Job = job_1527476268558_132947 with exception 'java.io. ...
- java.io.IOException: Could not find resource com/xxx/xxxMapper.xml
java.io.IOException: Could not find resource com/xxx/xxxMapper.xml 报错内容: org.apache.ibatis.exception ...
- mybatis错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml
在学习Mybatis的时候,参考网上的教程进行简单demo的搭建,配置的没有问题,然后出现了下面的错误! Exception in thread "main" java.lang. ...
- 关于 java.io.IOException: open failed: EACCES (Permission denied)
今天解决了一个问题,不得不来和大家分享.就是关于 java.io.IOException: open failed: EACCES (Permission denied)的问题,网上也有很多人把这个问 ...
- Dubbo java.io.IOException: Can not lock the registry cache file
跑单测用例的时候,以前执行成功的用例,运行时控制台仍然会报 dubbo 相关的错误: Failed to save registry store file, cause: Can not lock t ...
- elasticsearch中的java.io.IOException: 远程主机强迫关闭了一个现有的连接
[2018-07-31T14:29:41,289][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [9rTGh-y] caught exc ...
- AIO 开始不定时的抛异常: java.io.IOException: 指定的网络名不再可用
一天里会抛出几个这样的错误,但发现服务还在正常的运行. java.io.IOException: 指定的网络名不再可用. at sun.nio.ch.Iocp.translateErrorToIOEx ...
- 解决hiveserver2报错:java.io.IOException: Job status not available - Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
用户使用的sql: select count( distinct patient_id ) from argus.table_aa000612_641cd8ce_ceff_4ea0_9b27_0a3a ...
随机推荐
- XGBOOST in WIN64 安装
参考:https://blog.csdn.net/zyghs/article/details/50897716 环境 platform:windows 10,64位 Python: Python3.7 ...
- PHP 求两个日期之间相差的天数、月数
<?php /** * 求两个日期之间相差的天数 * (针对1970年1月1日之后,求之前可以采用泰勒公式) * @param string $day1 * @param string $day ...
- 【异常】azkaban.executor.ExecutorManagerException: No active executors found
1 azkaban启动异常 没有找到活动的executors,需在MySQL数据库里设置端口为12321的executors表的active为1 update azkaban.executors ...
- day01_人类社会货币的演变
1.货币的自然演变 1.1:从实物货币(贝壳.金银等一般等价物的稀有性等价于被交换物品的价值)---纸质货币(国家信用背书,使得一文不值的纸币可以兑换价值百元的商品)---记账货币(微信.二维码.银行 ...
- linux-2.6.38 input子系统(用输入子系统实现按键操作)
一.设备驱动程序 在上一篇随笔中已经分析,linux输入子系统分为设备驱动层.核心层和事件层.要利用linux内核中自带的输入子系统实现一个某个设备的操作,我们一般只需要完成驱动层的程序即可,核心层和 ...
- Linux(Ubuntu)安装ssh服务
在终端(Ctrl + Alt + T )输入 $ps -e | grep ssh 看到 “ ssh-agent ” 和 “sshd” ,表示没有安装服务,或没有开机启动 1.安装SSH 输入:sudo ...
- IO流大文件拷贝
String resourcesPath="f:/a.grd"; String targetPath=" ...
- vim + oh-my-zsh + git搭建开发环境
vim + oh-my-zsh + git配置开发环境 vim配置 安装vundle 使用vundle作为插件管理器,使用前先安装vundle mkdir -p ~/.vim/bundle git c ...
- P2051 [AHOI2009]中国象棋 大力DP
状压个啥$qwq$ 思路:大力$DP$ 提交:2次(自信的开了$int$) 题解:(见注释) #include<cstdio> #include<iostream> using ...
- Codevs 2188 最长上升子序列(变式)
2188 最长上升子序列 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题目描述 Description LIS问题是最经典的动态规划基础问题之一.如果要求一个 ...