创建位图的 HttpSUrlConnection 出现 SSL 错误
我正在尝试从网络获取图像并将其显示在 imageview
我的问题是,如果 url 是 HTTP,我可以获取图像,但如果 url 是 HTTPS,则不能获取图像
我正在使用以下代码:-
Bitmap bitmap = null;
InputStream in = null;
try {
URL url = new URL(URL);
URLConnection conn = url.openConnection();
// HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.connect();
in = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
I am trying to fetch image from net and display it in imageview
My problem is that i am able to fetch image if the url is HTTP but not if url is HTTPS
I am using the following code :-
Bitmap bitmap = null;
InputStream in = null;
try {
URL url = new URL(URL);
URLConnection conn = url.openConnection();
// HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.connect();
in = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你需要与 https 服务器进行一些握手,因为它是安全协议。您可以在这里找到解决方案:Https Connection Android
I guess you need to make some handshake with https server since it is secure protocol. You may find a solution here: Https Connection Android