Dowloading image resources from https with LoopJ AndroidAsyncHttp
Asked Answered
R

3

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);
    }
});
Reckless answered 9/10, 2013 at 10:27 Comment(4)
It'd be great if you could tell us what you've tried. Have you tried overriding onfailure or anything else?Euchology
Check the example on how to accept all certificates: github.com/loopj/android-async-http/issues/288Propertius
Not the best way to accept all certificates, no point in having HTTPS if you do that. You should have a look at : #12019181Ingoing
Use HttpsURLConnection developer.android.com/reference/javax/net/ssl/…Hymnody
F
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.

Flyover answered 24/10, 2013 at 11:31 Comment(0)
B
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);
Baxley answered 15/1, 2014 at 10:29 Comment(0)
D
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.

Derina answered 11/5, 2014 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.