Android api29网络请求报错

栏目: IOS · Android · 发布时间: 7年前

内容简介:Google表示,为保证用户数据和设备的安全,针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输,需要使用下一代(Transport Layer Security)传输层安全协议,而 Android Nougat 和 Oreo 则不受影响。Android P(API 29)HttpUrlConnection:

Google表示,为保证用户数据和设备的安全,针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输,需要使用下一代(Transport Layer Security)传输层安全协议,而 Android Nougat 和 Oreo 则不受影响。

Android P(API 29)

HttpUrlConnection:

W/System.err: java.io.IOException: Cleartext HTTP traffic to **** not permitted

Okhttp:

java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security policy

解决

方式1:

Manifest.xml总添加 android:usesCleartextTraffic="true"

<application

        android:usesCleartextTraffic="true"
>
        </application>

方式二:

在res下创建一个 xml 资源文件夹,然后创建一个 network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>

<network-security-config>

 <base-config cleartextTrafficPermitted="true" />

</network-security-config>

然后在manifest.xml添加

<application
      android:networkSecurityConfig="@xml/network_security_config">
</application>

以上所述就是小编给大家介绍的《Android api29网络请求报错》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

How to Design Programs

How to Design Programs

Matthias Felleisen、Robert Bruce Findler、Matthew Flatt、Shriram Krishnamurthi / The MIT Press / 2001-2-12 / 71.00美元

This introduction to programming places computer science in the core of a liberal arts education. Unlike other introductory books, it focuses on the program design process. This approach fosters a var......一起来看看 《How to Design Programs》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具