Android HttpURLConnection连接服务器异常

Android HttpURLConnection连接服务器异常,第1张

概述一、Andorid模拟器java.net.ConnectException:Failedtoconnecttolocalhost/127.0.0.1出现这种异常是localhost/127.0.0.1指机器本身,可以改为当前IP,打开cmd命令行,输入ipconfig回车,查看当前IP,更换localhost/127.0.0.1,再次运行AS。二、java.io.IOException:CleartextH

一、AndorID模拟器java.net.ConnectException: Failed to connect to localhost/127.0.0.1
出现这种异常是localhost/127.0.0.1指机器本身,可以改为当前IP,打开cmd命令行,输入ipconfig回车,查看当前IP,更换localhost/127.0.0.1,再次运行AS。

二、java.io.IOException: Cleartext http traffic to xxx.xxx.xxx.xxx not permitted
1.在res文件夹下创建一个xml文件夹,然后创建一个network_security_config.xml文件,文件内容如下:

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

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

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

问题二 原文:https://blog.csdn.net/gengkui9897/article/details/82863966

总结

以上是内存溢出为你收集整理的Android HttpURLConnection连接服务器异常全部内容,希望文章能够帮你解决Android HttpURLConnection连接服务器异常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115955.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存