cleartext HTTP traffic not permitted

简介: cleartext HTTP traffic not permitted

异常描述

在使用Android P(9.0)的机型上,如果我们的app使用的是Okhttp或HttpUrlConnection做网络请求时,会在logcat中报以下的错误.


原因

从android 9.0开始,网络请求默认不支持没有加密的明文传输.

解决方法

方法1

将http改为https.

方法2

在res/xml目录创建一个资源文件.

如果没有xml目录,先创建一个.

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true"/>
</network-security-config>

在AndroidManifest.xml清单文件的Application标签中添加networkSecurityConfig属性,引用上面创建的

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

这样我们的app就能正常的使用http请求了。


参考:https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted

https://developer.android.google.cn/training/articles/security-config#CleartextTrafficPermitted

相关文章
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2
4374 0
|
关系型数据库 PostgreSQL Ruby
HTTP 502: Whoops, GitLab is taking too much time to respond.
最近有台云上的服务器需要释放,然后上面跑的 gitlab 也要挪个地方,如在 docker 内运行,gitlab 镜像大约 1.56G,需占用 4G 以上的内存,因资源有限,于是借在其他的服务器上搭建环境(可用内存小于4G),然鹅启动的时候莫名出现 502,Excuse me?接着搜了一些 issue 博客上的解决方案(如修改端口、重启或 hup 某个服务)无果,后来在调整的过程中从日志里发现了一些信息。
12014 0
|
SQL JavaScript 关系型数据库
Client does not support authentication protocol requested by server
Client does not support authentication protocol requested by server
74 0
|
开发工具 数据安全/隐私保护
The request you have made requires authentication. (HTTP 401)
The request you have made requires authentication. (HTTP 401)
1378 0
The request you have made requires authentication. (HTTP 401)
|
Web App开发 安全 前端开发
Mixed Content: The page at was loaded over HTTPS, but requested an insecure imag
Mixed Content: The page at was loaded over HTTPS, but requested an insecure imag
467 0
Mixed Content: The page at was loaded over HTTPS, but requested an insecure imag
|
iOS开发 MacOS
curl: (4) A requested feature, protocol or option was not found
curl: (4) A requested feature, protocol or option was not found
276 0
curl: (4) A requested feature, protocol or option was not found
requests InsecureRequestWarning: Unverified HTTPS request is being made.
requests InsecureRequestWarning: Unverified HTTPS request is being made.
1240 0
|
Java 安全 网络安全
请求https错误: unable to find valid certification path to requested target
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/catoop/article/details/51155224 错误及原因 当Java客户端请求实现https协议的服务时,出现异常:’unable to find valid certification path to requested target’ 是因为服务期端的证书没有被认证,需要做的是把服务端证书导入到Java keystore。
8375 0
|
网络安全 微服务 Linux
The handler does not support client authentication certificates with this combination of libcurl (7.54.0) and its SSL backend ("LibreSSL/2.0.20")
NET Core的跨平台大家已经有目共睹,而在MAC平台上做开发已经成为目前的主流,无论哪种语言。 在一次微服务移植的过程中,客户端需要发送Http自定义混合验证,在MonoNET上没有任何问题,而移植到NET Core 2.0并运行,就出现了错误:The handler does not support client authentication certificates with this combination of libcurl (7.54.0) and its SSL backend ("LibreSSL/2.0.20")。
1210 0
下一篇
无影云桌面