Android ECONNREFUSED(连接被拒绝)

Android ECONNREFUSED (Connection refused)

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

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;

我尝试使用用户名和密码对登录时收到以下错误消息。

[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 可以通过网络浏览器访问,所以我认为端口 80 是可以的。 文件路径也OK。我检查了数据库,它是 运行 正确的。 我在清单文件中设置了必要的权限。

你的phone和你用ip号连接的电脑在同一个网络吗?服务器在 public 互联网上吗?当我忘记将我的 phone 放在我的本地 wifi 网络上并且它想连接到我本地网络上的服务器时,我收到此错误。

添加到 Christine 的回答中:

我也遇到过类似的情况。我试图通过它的热点连接到另一个 android 设备。即使他们连接到同一个网络,我也遇到了 "connect failed: ECONNREFUSED (Connection refused)".

的问题

在这上面糟蹋了几天之后,我意识到我的客户端设备已连接到移动互联网 also.That 意思是,我的移动数据 ON.

我把它 关了 和 Viola !

确保您没有连接到任何其他网络。

张贴此内容以防对任何人有所帮助。