2019-05-27 android9.0与http访问

9.0 http报错信息

httpurlconnection

1 cleartext http traffic not permitted

okhttp

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

原因:权限

解决方法

在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml

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

<network-security-config>

 <base-config cleartextTrafficPermitted="true" />

</network-security-config>

AndroidManifest文件下application下增加配置

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

9.0类缺失问题

报错

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.impl.client.DefaultHttpClient" on path: DexPathList

原因:库被移除

解决方法

<application 
...
>
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application >

转载于:https://www.jianshu.com/p/72d89a74ea98

猜你喜欢

转载自blog.csdn.net/weixin_34144450/article/details/91108106