简体   繁体   English

Android ECONNREFUSED(拒绝连接)

[英]Android ECONNREFUSED (Connection refused)

I have tried to send data to server with this code from my android application. 我试图通过我的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;

I got following error message when try to login with username and password pair. 尝试使用用户名和密码对登录时出现以下错误消息。

[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) [套接字] [0]连接/ myip:80; LocalPort = 33049(0)关闭[套接字] [/ 0.0.0.0:33049] W / System.err:org.apache.http.conn.HttpHostConnectException:与http的连接: // myip被拒绝原因:java.net.ConnectException:90000ms之后无法连接到/ myip(端口80):isConnected失败:ECONNREFUSED(连接被拒绝)

myip is accessible via web browser, so I think port 80 is OK. 可通过Web浏览器访问myip,因此我认为端口80可以。 File path is also OK. 文件路径也可以。 I checked the databse and it is running properly. 我检查了数据库,它运行正常。 I set necessary permissions in Manifest file. 我在清单文件中设置了必要的权限。

Is your phone on the same network as the computer where you connect with the ip number? 您的电话是否与使用IP地址连接的计算机位于同一网络上? 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. 当我忘记将手机放在本地wifi网络上并且想要连接到本地网络上的服务器时,会出现此错误。

Adding to Christine's answer: 添加到克里斯汀的答案:

I had a similar situation. 我也有类似的情况。 I was trying to connect to another android device through it's hotspot. 我正在尝试通过其热点连接到另一个Android设备。 Even though they were connected in to the same network, I encountered this problem of "connect failed: ECONNREFUSED (Connection refused)". 即使他们已连接到同一网络,我也遇到了“连接失败:ECONNREFUSED(连接被拒绝)”的问题。

After spoiling a couple of days on this, I realized that my client device was connected to mobile Internet also.That means, my mobile data was ON . 经过几天的破坏,我意识到我的客户端设备也连接到了移动互联网,这意味着我的移动数据已打开

I turned it OFF and Viola ! 我把它关了 ,中提琴!

Make sure you are not connected to any other networks. 确保您未连接到任何其他网络。

Posted this in case it may help anybody. 发布此内容以防万一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android WiFi Direct-客户端/服务器-ECONNREFUSED(拒绝连接)更新 - Android WiFi Direct - client/server - ECONNREFUSED (Connection refused) UPDATE 带有 Java ECONNREFUSED 的 Heroku Websockets(连接被拒绝) - Heroku Websockets with Java ECONNREFUSED (Connection refused) 在Android Studio中获取连接被拒绝(连接被拒绝) - Getting Connection refused (Connection refused) in android studio Android:连接被拒绝错误 - Android: Connection refused error Android Socket连接遭拒绝 - Android Socket connection refused Android http 连接被拒绝 - Android http connection refused TCP套接字连接在Android上被拒绝 - TCP socket connection refused on Android Android Web Service连接被拒绝 - Android Web Service connection refused IOException java.net.ConnectException:无法连接到/127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) - IOException java.net.ConnectException: failed to connect to /127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) java.net.ConnectException:无法连接到/192.168.10.110连接失败:ECONNREFUSED(连接被拒绝 - java.net.ConnectException: failed to connect to /192.168.10.110 connect failed: ECONNREFUSED (Connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM