tags:

views:

547

answers:

2
public static final String readURL(String url)throws Throwable
{
  try {
   InputStream in = (InputStream) fetch(url);
   byte[] bArr = readBytes(in);
   return new String(bArr);
  } catch (Throwable e) {
   throw e;
   }
}


public static final Object fetch(String address) throws MalformedURLException,IOException {
 URL url = new URL(address);
 Object content = url.getContent();
 return content;
}

I am behind a proxy and when I try

readURL("http://abc.com")

to access URL http://abc.com it throws java.net.UnknownHostException: I have:

<uses-permission android:name="android.permission.INTERNET" />

in manifest file.

Any quick solutions?

A: 

It is possible that fetch does not do the necessary DNS lookups. If you nslookup abc.com you get a redirect to www.go.com. This may be the problem.

Andrew Cox
+2  A: 
Proxy proxy = new Proxy(Proxy.DIRECT,
    new InetSocketAddress(proxyHost, proxyPort));
url.openConnection(proxy);

or

System.setProperty("http.proxyHost", "my.proxyhost.com");
System.setProperty("http.proxyPort", "1234");
Bozho
i love the above code.
Faisal khan