Java Android连接到http服务器:即使我声明了我的在线服务器,Eclipse也会抛出关于localhost的异常?
我正在eclipse中从事一个android项目,我有以下问题 为什么下面的代码会引发异常Java Android连接到http服务器:即使我声明了我的在线服务器,Eclipse也会抛出关于localhost的异常?,java,android,mysql,url,connection,Java,Android,Mysql,Url,Connection,我正在eclipse中从事一个android项目,我有以下问题 为什么下面的代码会引发异常 W/System.err(5354): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused) 即使我的变量身份验证\服务器\地址不是localhost,而是一个在线服务器地址,类似于 应连接到我的服务器
W/System.err(5354): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused)
即使我的变量身份验证\服务器\地址不是localhost,而是一个在线服务器地址,类似于
应连接到我的服务器的代码示例:
url = new URL(AUTHENTICATION_SERVER_ADDRESS);
HttpURLConnection connection;
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
在PrintWriter的行中引发异常。我怎样才能解决这个问题?谢谢 Dnt使用本地主机,使用Ip地址
e、 字符串URL=http://127.0.0.1thats 您的ip:1802测试您的端口/。这很奇怪,我使用的是url=new url,但错误说明了有关localhost的内容,当无法建立连接时,这是默认错误吗?您可以尝试127.0.0.1,它适用于设备模拟器本身。您尝试过您的ip和端口吗??dnt在您的身份验证\u服务器\u地址中写入localhost我没有在任何地方使用localhost,只有错误返回localhost…我没有给出端口号,只有:'String AUTHENTICATION\u SERVER\u ADDRESS=http://myserver.com/folder/;' 然后是“url=新的url身份验证\服务器\地址;”它无法访问您的局域网。只需在局域网上添加服务器的IP,您就可以从仿真器访问它: