HttpsURLConnection failing intermittently to the same URL
Posted
by Arkaitz Jimenez
on Stack Overflow
See other posts from Stack Overflow
or by Arkaitz Jimenez
Published on 2010-05-15T18:41:42Z
Indexed on
2010/05/15
18:44 UTC
Read the original article
Hit count: 222
I think I'm experiencing the same as
http://groups.google.com/group/android-developers/msg/9d37d64aad0ee357
This is Android 1.5 SDK.
I happen to call several times below code(which is in a method) with
the same url and it fails intermittently.
When it fails, there is no exception, the stream is empty so the
readConnection fails, and getResponseCode returns -1.
Global caching is disabled, setDefaultUseCaches(false);
I suppose there must be some kind of url connection object pool somewhere.
Any idea on how can I workaround this?
HttpURLConnection connection = null;
try {
URL url = new URL(this.url);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "basic " +
Base64Coder.encodeString(user + ":" + password));
connection.setRequestProperty("User-Agent", userAgent);
connection.connect();
readConnection(connection.getInputStream());
connection.disconnect();
} catch (IOException ex) {
reportException(ex, connection.getResponseCode())
} catch (ParserException ex) {
reportException(ex, connection.getResponseCode())
}
© Stack Overflow or respective owner