httpResponse / httppost连接被拒绝警告,然后因此而发生错误

时间:2013-06-26 10:48:50

标签: android xml-parsing http-post

我收到了这个警告:

    06-26 15:19:09.689: W/System.err(611): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8080 refused
06-26 15:19:09.689: W/System.err(611):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
06-26 15:19:09.719: W/System.err(611):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
06-26 15:19:09.719: W/System.err(611):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
06-26 15:19:09.719: W/System.err(611):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
06-26 15:19:09.739: W/System.err(611):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-26 15:19:09.739: W/System.err(611):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-26 15:19:09.739: W/System.err(611):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

尝试在非ui类中执行此代码时:

1    public String getXmlFromUrl(String url) { 
2            String xml = null; 
3            try { 
4                HttpClient httpClient = new DefaultHttpClient();
5                HttpPost httpPost = new HttpPost(url); 
6                HttpResponse httpResponse = httpClient.execute(httpPost); 
7                HttpEntity httpEntity = httpResponse.getEntity(); 
8                xml = EntityUtils.toString(httpEntity); 
9            } catch (UnsupportedEncodingException e) { 
10                e.printStackTrace(); 
11            } catch (ClientProtocolException e) { 
12               e.printStackTrace(); 
13            } catch (IOException e) { 
14                e.printStackTrace(); 
15            } 
16            return xml; 
17        }

我正在提供网址

http://10.0.2.2:8080/Mysite/xxx   

这里有什么问题。为什么我会收到这个错误。

因此,“xml”字符串返回null,这进一步导致我的应用程序出错。

我调试了我的应用程序,我可以看到我捕获异常IOException,因此我将从第6行到第13行。

0 个答案:

没有答案