How to fix this UnknownHostException event?

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'm for the proxy and when I try

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

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

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

in the manifest file.

Any quick fixes?

+5
source share
4 answers
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");
+13
source

If you use the application on the Emulator , follow these steps:

1) Close all running emulators.

2) Clean up the project and close Eclipse.

3) Run the eclipse again.

4) Create a new emulator and run the project.

Here it is! worked for me!

+1
source

, DNS-. nslookup abc.com, www.go.com. .

0

, - . , IE FF , .

  • adb shell

  • sqlite3/data/data/com.google.android.providers.settings/databases/settings.db

  • sqlite > INSERT INTO (99, http_proxy ',' proxy: port ');
  • sqlite > SELECT * FROM system;

.

Check out this link: A proxy that requires authentication with an Android emulator

0
source

All Articles