HttpsURLConnection abort with one url

I think I'm experiencing the same as http://groups.google.com/group/android-developers/msg/9d37d64aad0ee357
This is the Android 1.5 SDK. I sometimes call several times below the code (which is in the method) with the same url and it breaks intermittently.
When it fails, there is no exception, the stream is empty, so readConnection fails and getResponseCode returns -1.
Global caching disabled, setDefaultUseCaches (false);

I am guessing there must be some sort of pool of url connection objects somewhere.

Any idea on how I can get around 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())
    } 

      

+2


a source to share


2 answers


The way I fixed this issue was to add the line below ...

System.setProperty("http.keepAlive", "false");

      

... in front of my connection line ...



connection = (HttpURLConnection) url.openConnection();

      

Good luck!

+3


a source


if getResponseCode returns -1 it means there was some kind of connection error.



0


a source







All Articles