Dowloading image resources from https with LoopJ AndroidAsyncHttp
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);
}
});
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.
我希望这段代码能解决你的问题
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);
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.
链接地址: http://www.djcxy.com/p/74892.html上一篇: 哈斯克尔和可变结构的表现