Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

java - Android ECONNREFUSED (Connection refused)

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 + "
");
    }
    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)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...