1. Check out our companion app, Forums for Android! Download from Google Play

HttpsURLConnection only works once!

Discussion in 'Application Development' started by auxone, Feb 8, 2010.

  1. auxone

    auxone New Member
    Thread Starter

    Feb 8, 2010
    I have a HttpsURLConnection class for Android that works only once for each time the app is run. On the second time, even if I use the same class instance, or if I create a separate instance of it, the connection is never made and getResponseCode() is -1.

    Since my class is kinda complex, I've been working with the "solution" I found here: need help on https (code for http included) :: anddev.org - Android Development Community | Android Tutorials but I break out the try/catch into a function so I can call it twice. Even then, it only works the first time.

    I've been trying different permutations and examples found online (with and without the fake certificate hack) that supposedly work, but all with the same results.

    Everything I've tried work perfectly with HttpURLConnection and http:// but when I move it over to https:// and HttpsURLConnection, it only works once per app launch.

    Anyone have any ideas? I'm sufficiently frustrated after days of this.

    Thanks in advance


  2. nishantnair

    nishantnair New Member

    Feb 11, 2012
    HttpsURLConnection class in Android works fine in android 2.3.
    you can use this
    System.setProperty("http.keepAlive", "false");
    before initialization of your connection.

    If you want to support android 2.1 or 2.2 Apache Http Client is better option.
    alostpacket likes this.

Share This Page