得到“org.apache.http.conn.httphostconnectexception连接到http:// xxxx:88 / mobile.php被拒绝(getting "org

编程入门 行业动态 更新时间:2024-10-23 04:42:19
得到“org.apache.http.conn.httphostconnectexception连接到http:// xxxx:88 / mobile.php被拒绝(getting "org.apache.http.conn.httphostconnectexception connection to http://x.x.x.x:88/mobile.php refused)

我使用xampp设置了一个MySql服务器,我正在创建一个连接数据库的Android应用程序。 我可以使用外部的MYSQL Workbench和ODBC连接器毫无问题地连接,并且可以无误地推/拉数据。 当与EMULATED手机连接时,我在DDMS中收到“org.apache.http.conn.httphostconnectexception连接到http:// xxxx:88 / mobile.php denied ”。 知道为什么会这样吗???

允许Internet未启用...现在,只是验证,清理并重新启动,现在我收到“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()); } }

I've setup a MySql server using xampp, I am creating an android app to connect to the database. I can connect without a problem using MYSQL Workbench and ODBC connector from off site and ably to push/pull data without errors. when connecting with the EMULATED phone I am getting "org.apache.http.conn.httphostconnectexception connection to http://x.x.x.x:88/mobile.php refused" in the DDMS. Any idea why this is happening???

Allow Internet wasn't turned on... it is now , just verified, cleaned and relaunched, now I am getting "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()); } }

最满意答案

使这项工作的步骤:

为您的清单添加INTERNET权限 确保服务器端没有阻止防火墙或代理 添加httpPost.setHeader("Accept", "application/json"); 在httpPost声明之后

Steps to make this work:

Add INTERNET permission to your Manifest Make sure no firewall or proxy is blocking from server side add httpPost.setHeader("Accept", "application/json"); after httpPost declaration

更多推荐

本文发布于:2023-08-03 12:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1389335.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   被拒   httphostconnectexception   http   conn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!