1. Download our Official Android App: Forums for Android!

Apps HttpsURLConnection only works once!

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

  1. auxone

    auxone Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Feb 8, 2010

    Feb 8, 2010
    1
    0
    5
    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
     

    Advertisement

  2. nishantnair

    nishantnair Lurker
    Rank:
    None
    Points:
    6
    Posts:
    1
    Joined:
    Feb 11, 2012

    Feb 11, 2012
    1
    1
    6
    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

Loading...