Android Unknown HostException Facebook SDK

Here is the situation. My application is working fine and can establish connections with URLs. BUT a few hours after launching the application, suddenly Facebook requests give me the following error.

09-26 10:01:25.175: W/System.err(252): java.net.UnknownHostException: Host is unresolved: xyz.com:80
09-26 10:01:25.175: W/System.err(252):  at java.net.Socket.connect(Socket.java:1037)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1051)
09-26 10:01:25.175: W/System.err(252):  at java.net.URL.openStream(URL.java:653)

This error occurs both in the application and in the emulator. When I exit my application and reconnect to Facebook, the connections work again.

I should note: When I establish connections with my own server, there are no problems.

This error is caused by the following lines:

mAsyncFacebookRunner.request("fql", paramaters,
                new FQLRequestListener());
+5
source share
3 answers

java.net.UnknownHostException , IP- , . ( , API , HttpUrlConnection DefaultHttpClient), , , , Android, DNS TTL:

7904: Android TTL DNS 10

Android 4.1, . API InetAddress:

DNS-

Android 4.0 (Ice Cream Sandwich) DNS InetAddress, C, , DNS TTL . C, DNS TTL .

Android Android DNS Java networkaddress.cache.ttl networkaddress.cache.negative.ttl, . JavaDoc :

/**
 * ... ...
 *
 * <h4>DNS caching</h4>
 * <p>On Android, addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are
 * cached for 10 seconds. The underlying C library or OS may cache for longer, but you can control
 * the Java-level caching with the usual {@code "networkaddress.cache.ttl"} and
 * {@code "networkaddress.cache.negative.ttl"} system properties. These are parsed as integer
 * numbers of seconds, where the special value 0 means "don't cache" and -1 means "cache forever".
 *
 * ... ...
 */

:

, , Android.

+4

DNS TTL.

Facebook Util.java [ SDK Facebook], . stackoverflow.

openUrl (String url, String method, Bundle params)

,

 HttpURLConnection conn =
            (HttpURLConnection) new URL(url).openConnection();

,

        try {
            InetAddress i = InetAddress.getByName(url);
        } catch (UnknownHostException e1) {
            e1.printStackTrace();
        }

        HttpURLConnection conn = (HttpURLConnection) new URL(url)
                .openConnection();
        conn.setConnectTimeout(50000);

.

+2

, ..... , , httpClient.getConnectionManager(). shutdown(); .

+2

All Articles