gpt4 book ai didi

php - 获取“org.apache.http.conn.httphostconnectexception 连接到 http ://x. x.x.x :88/mobile. php 被拒绝

转载 作者:行者123 更新时间:2023-11-29 23:28:26 25 4
gpt4 key购买 nike

我已经使用 xampp 设置了一个 MySql 服务器,我正在创建一个 Android 应用程序来连接到数据库。我可以使用 MYSQL Workbench 和 ODBC 连接器从异地进行连接,并且能够毫无错误地推/拉数据。当与模拟手机连接时,我在 DDMS 中收到“org.apache.http.conn.httphostconnectexception 连接到 http://x.x.x.x:88/mobile.php 被拒绝”。知道为什么会发生这种情况吗???

允许互联网未打开...现在已打开,刚刚经过验证、清理并重新启动,现在我收到“ClientProtocolException”。

public void getData() {
String result = "";
InputStream isr = null;
try {
HttpClient httpclient = new DefaultHttpClient();
///external ip address not local host or trying inside a local network
HttpPost httpost = new HttpPost("http://x.x.x.x:88/mobile.php");
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
} catch (Exception e) {
Log.e("log.tag", "Error in http connection " + e.toString());
resultView.setText("Could not connect to Database");
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
isr, "iso=8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();

result = sb.toString();
} catch (Exception e) {
Log.e("log.tag", "Error converting result " + e.toString());
}
try {
String s = "";
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json = jArray.getJSONObject(i);
s = s + "User :" + json.getString("UserName");
}
resultView.setText(s);
} catch (Exception e) {
Log.e("log.tag", "Error Parsing Data " + e.toString());
}

}

最佳答案

实现此功能的步骤:

  1. 将 INTERNET 权限添加到您的 list 中
  2. 确保没有防火墙或代理阻止服务器端
  3. httpPost 声明之后添加 httpPost.setHeader("Accept", "application/json");

关于php - 获取“org.apache.http.conn.httphostconnectexception 连接到 http ://x. x.x.x :88/mobile. php 被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26768037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com