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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…