美文网首页android
2019-05-27 android9.0与http访问

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

作者: voif | 来源:发表于2019-05-27 16:42 被阅读0次

    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 >
    

    相关文章

      网友评论

        本文标题:2019-05-27 android9.0与http访问

        本文链接:https://www.haomeiwen.com/subject/goghtctx.html