Android ECONNREFUSED(拒绝连接) [英] Android ECONNREFUSED (Connection refused)

查看:696
本文介绍了Android ECONNREFUSED(拒绝连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此代码从我的android应用程序向服务器发送数据.

I have tried to send data to server with this code from my android application.

try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://myip/adminlogin.php");
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    HttpResponse response = httpClient.execute(httpPost);

    HttpEntity entity = response.getEntity();

    is = entity.getContent();

    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
    StringBuilder sb = new StringBuilder();

    String line = null;
    while ((line = reader.readLine()) != null)
    {
        sb.append(line + "\n");
    }
    result = sb.toString();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
return result;

尝试使用用户名和密码对登录时出现以下错误消息.

I got following error message when try to login with username and password pair.

[套接字] [0]连接/myip:80; LocalPort = 33049(0)关闭 [socket] [/0.0.0.0:33049] W/System.err: org.apache.http.conn.HttpHostConnectException:连接到 http://myip 拒绝原因:java.net.ConnectException:未能 90000ms后连接到/myip(端口80):isConnected失败: ECONNREFUSED(连接被拒绝)

[socket][0] connection /myip:80;LocalPort=33049(0) close [socket][/0.0.0.0:33049] W/System.err: org.apache.http.conn.HttpHostConnectException: Connection to http://myip refused Caused by: java.net.ConnectException: failed to connect to /myip (port 80) after 90000ms: isConnected failed: ECONNREFUSED (Connection refused)

myip可通过Web浏览器访问,因此我认为端口80可以. 文件路径也可以.我检查了数据库,它运行正常. 我在清单文件中设置了必要的权限.

myip is accessible via web browser, so I think port 80 is OK. File path is also OK. I checked the databse and it is running properly. I set necessary permissions in Manifest file.

推荐答案

您的电话是否与使用IP地址连接的计算机位于同一网络上?服务器在公共互联网上吗?当我忘记将手机放在本地wifi网络上并且想要连接到本地网络上的服务器时,会出现此错误.

Is your phone on the same network as the computer where you connect with the ip number? Is the server on the public internet? I get this error when I forget to put my phone on my local wifi network and it wants to connect to a server on my local network.

这篇关于Android ECONNREFUSED(拒绝连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆