开发者

Android: Has anyone encountered the localhost HttpClient Connection Refused error?

I was just wondering if anyone solved this problem. Googling gives tons of posts having this question but not one with a proper reply. I tried literally every combination of the following two pieces of code with and without proxy:

/*********** URL METHOD ***************/
//URLConnection conn = aURL.openConnection(); 
//conn.connect(); 
//InputStre开发者_Go百科am is = conn.getInputStream(); 

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

InputStream is = resp.getEntity().getContent();

I am trying to connect to a site on my intranet (its not localhost). I've tried the following:

  1. Setting Proxy inside Eclipse settings
  2. Setting my own localhost and writing a small php script that takes the url, connects to it and then gets the file from the intranet site - This works from the Browser though! It does not work when I use the 10.0.2.2 IP address

Any thoughts?


You should check out this : http://developer.android.com/guide/appendix/faq/commontasks.html#localhostalias

(use the alias "10.0.2.2" instead of "localhost" or "127.0.0.1")


You need to give proper permissions to the app in order for it to use internet.

try adding following line in your application manifest file.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yourpackage"
    android:versionCode="1"
    android:versionName="1.0" >
    ..
    ..
    <uses-permission android:name="android.permission.INTERNET" />
</manisfest>

At least this worked for me.


The only thing that helps me is to shut down Eclipse and then kill adb.exe. After you restart Eclipse it (usually) goes away. Until next time.


This sounds lame but do check for all the connections on both the device as well as your workstation...I had restarted my device and the Wifi connection on my device went off

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜