我试图从我的 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 denied 原因:java.net.ConnectException:在 90000 毫秒后无法连接到 /myip(端口 80):isConnected 失败:ECONNREFUSED(连接被拒绝)
myip 可以通过网络浏览器访问,所以我认为端口 80 是可以的。文件路径也可以。我检查了数据库,它运行正常。我在清单文件中设置了必要的权限。