7

I'm using LoopJ AndroidAsyncHttp to download images but when I try it for HTTPS URLs I get no response. Code:

AsyncHttpClient client = new AsyncHttpClient();
client.get(httpsUrlString, new BinaryHttpResponseHandler(allowedContentTypes) {
    @Override
    public void onSuccess(byte[] fileData) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(fileData, 0, fileData.length);
        image.setImageBitmap(bitmap);
    }
});
Gabe
  • 5,997
  • 5
  • 46
  • 92
luigi23
  • 305
  • 2
  • 9
  • 1
    It'd be great if you could tell us what you've tried. Have you tried overriding onfailure or anything else? – OrhanC1 Oct 11 '13 at 16:57
  • 1
    Check the example on how to accept all certificates: https://github.com/loopj/android-async-http/issues/288 – Juuso Ohtonen Oct 13 '13 at 07:14
  • 1
    Not the best way to accept all certificates, no point in having HTTPS if you do that. You should have a look at : http://stackoverflow.com/questions/12018681/android-tls-connection-and-self-signed-certificate – Adnan Mulla Oct 22 '13 at 08:03
  • Use HttpsURLConnection http://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html – Himanshu Joshi Oct 22 '13 at 09:16

3 Answers3

4

There are a few open source libraries that do asynchronous image loading. They do not only take care of the download, but also caching and multithreading.

All in all, it is much more handy to use this libraries than to try to write all that code on your own. Right now it is only downloading an image, but in the future you may want caching, etc.

I suggest you take a look at picasso or volley, picasso is simpler to use, but volley has a lot more functionality.

shalafi
  • 3,926
  • 2
  • 23
  • 27
0

I hope this code can solve your problem

KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);

MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore);
socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

httpClient.setTimeout(30 * 1000);
httpClient.setSSLSocketFactory(socketFactory);
Khai Nguyen
  • 3,065
  • 1
  • 31
  • 24
0

a little bit late but you can accept all cerificates this way ..

AsyncHttpClient client = new AsyncHttpClient(true, 80, 443);

in your logs you will see this..

AsyncHttpClient﹕ Beware! Using the fix is insecure, as it doesn't verify SSL certificates.

Alexander Sidikov Pfeif
  • 2,418
  • 1
  • 20
  • 35