【发布时间】:2017-11-30 16:55:26
【问题描述】:
我已尝试使用此代码从我的 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] 连接 /myip:80;LocalPort=33049(0) 关闭 [socket][/0.0.0.0:33049] W/System.err: org.apache.http.conn.HttpHostConnectException:连接到 http://myip 拒绝原因:java.net.ConnectException:未能 90000 毫秒后连接到 /myip(端口 80):isConnected 失败: ECONNREFUSED(连接被拒绝)
myip 可以通过网络浏览器访问,所以我认为端口 80 是可以的。 文件路径也可以。我检查了数据库,它运行正常。 我在 Manifest 文件中设置了必要的权限。
【问题讨论】:
-
消息的意思是:“这个IP地址没有服务器”。
-
@Christine :有,因为我再次检查了链接,它已粘贴到应用程序中。
-
对我来说,这看起来像是超时问题——请参阅错误消息的“90000 毫秒后”部分。当您说 myip 可通过网络浏览器访问时,您是指运行应用程序的设备上的网络浏览器吗?
-
@Christine :谢谢,这是问题所在,也是我的错。再次感谢您的帮助!
-
@Christine : 抱歉,我尝试加载一些页面,但是是的,这是网络问题。
标签: java android econnrefused