Android:有没有人遇到localhost HttpClient Connection Refused错误?

Leg*_*end 2 android http

我只是想知道是否有人解决了这个问题.谷歌搜索提供了大量的帖子有这个问题,但没有一个有适当的答复.我试着使用和不使用代理的以下两段代码的每个组合:

/*********** URL METHOD ***************/
//URLConnection conn = aURL.openConnection(); 
//conn.connect(); 
//InputStream is = conn.getInputStream(); 

/*********** HTTP METHOD ***************/
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(urlString);
HttpResponse resp = client.execute(get);

InputStream is = resp.getEntity().getContent();
Run Code Online (Sandbox Code Playgroud)

我正在尝试连接到我的Intranet上的站点(它不是localhost).我尝试过以下方法:

  1. 在Eclipse设置中设置代理
  2. 设置我自己的localhost并编写一个带有url的小php脚本,连接到它然后从Intranet站点获取文件 - 这可以从浏览器中运行!当我使用10.0.2.2 IP地址时,它不起作用

有什么想法吗?

let*_*nda 13

你应该看看这个:http: //developer.android.com/guide/appendix/faq/commontasks.html#localhostalias

(使用别名"10.0.2.2"而不是"localhost"或"127.0.0.1")