java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted

转 https://blog.csdn.net/nidongde521/article/details/86496804

Android9.0 默认是禁止所有的http

请求的,需要在代码中设置如下代码才可以正常进行网络请求: android:usesCleartextTraffic="true"。如图

  1.  
    <application
  2.  
    android:name="xxxx.xxxx.xxx.xxx"
  3.  
    android:allowBackup="true"
  4.  
    android:icon="@drawable/ic_launcher"
  5.  
    android:label="@string/app_name"
  6.  
    android:theme="@style/AppBaseTheme"
  7.  
    android:usesCleartextTraffic="true">
 
其它:

Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法

 
 
转载https://blog.csdn.net/gengkui9897/article/details/82863966

前言:为保证用户数据和设备的安全,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文件,文件内容如下:

  1.  
    <?xml version="1.0" encoding="utf-8"?>
  2.  
    <network-security-config>
  3.  
    <base-config cleartextTrafficPermitted="true" />
  4.  
    </network-security-config>

2.接着,在AndroidManifest.xml文件下的application标签增加以下属性:

  1.  
    <application
  2.  
    ...
  3.  
    android:networkSecurityConfig="@xml/network_security_config"
  4.  
    ...
  5.  
    />

完成,这个时候App就可以访问网络了。

 

java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted的更多相关文章

  1. Caused by : java.io.IOException: Cleartext HTTP traffic to 《“url”》 not permitted

    一.问题原因: 根本原因是从Android9.0开始,出于完全因素考虑,默认不再支持http网络请求,需要使用 https. 二.解决方案: 解决的基本思路是:对指定的网址进行过滤,强制允许指定网址继 ...

  2. 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. ...

  3. 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 ...

  4. mybatis错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml

    在学习Mybatis的时候,参考网上的教程进行简单demo的搭建,配置的没有问题,然后出现了下面的错误! Exception in thread "main" java.lang. ...

  5. 关于 java.io.IOException: open failed: EACCES (Permission denied)

    今天解决了一个问题,不得不来和大家分享.就是关于 java.io.IOException: open failed: EACCES (Permission denied)的问题,网上也有很多人把这个问 ...

  6. Dubbo java.io.IOException: Can not lock the registry cache file

    跑单测用例的时候,以前执行成功的用例,运行时控制台仍然会报 dubbo 相关的错误: Failed to save registry store file, cause: Can not lock t ...

  7. elasticsearch中的java.io.IOException: 远程主机强迫关闭了一个现有的连接

    [2018-07-31T14:29:41,289][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [9rTGh-y] caught exc ...

  8. AIO 开始不定时的抛异常: java.io.IOException: 指定的网络名不再可用

    一天里会抛出几个这样的错误,但发现服务还在正常的运行. java.io.IOException: 指定的网络名不再可用. at sun.nio.ch.Iocp.translateErrorToIOEx ...

  9. 解决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 ...

随机推荐

  1. zabbix环境mysql分区表管理历史数据_python实现

    zabbix添加数据库表partition zabbix系统自身有housekeeper进程来清除超过保留时间的数据,但是数据量上来之后就会比较影响性能,因此可以使用mysql的表分区来解决这个问题, ...

  2. 批量kill指定名称的进程

     以Airflow举例: ps -ef | grep “airflow" | grep -v grep | cut -c 9-15 | xargs kill -9   分析: ps -ef  ...

  3. centos 6.4系统双网卡绑定配置详解

    Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡(需要交换机支持),这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是两块网卡具有相同的IP地址而并行链接聚合成一个逻辑链路工作. ...

  4. Linux--查询文件的第几行到第几行命令

    cat catalina.out | tail -n +14000 | head -n 10000 | sort | uniq -c linux 如何显示一个文件的某几行(中间几行)[一]从第3000 ...

  5. Navicat Premium 12连接mysql-8.0.15-winx64 出现2059异常

    错误

  6. “景驰科技杯”2018年华南理工大学程序设计竞赛 G. Youhane as "Bang Riot"(斜率DP)

    题目链接:https://www.nowcoder.com/acm/contest/94/G 题意:中文题目,见链接 题解:设 sum[i] 为 a[i] 的前缀和,可得公式 dp[i] = min( ...

  7. jdk8 时间日期工具类(转)

    package com.changfu.common.util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jav ...

  8. sudo/su

    linux用户分为根用户/ 普通用户 系统用户 根用户和普通用户是可以实际登录到系统中的,普通用户是没办法使用useradd添加新用户的,只有根用户有权限 当然,也可以使用su su 是切换用户的意思 ...

  9. Linux 文件查看

    链接:https://www.nowcoder.com/questionTerminal/fb39fbeec71f43a3a16edeb0bc98f4ac 来源:牛客网 /var/log/messag ...

  10. [Luogu] 宝藏

    https://www.luogu.org/problemnew/show/P3959 模拟退火解法 发现prim求最小生成树是明显错误的 因为prim每次要取出边权最小的点 然而在这道T中这样做不一 ...