【发布时间】:2017-07-31 16:40:14
【问题描述】:
我得到一个受密码保护的图像 url。我知道如何使用 Authenticator 执行此操作,但我想使用 Picasso 执行此操作。 谁能告诉我如何使用 Picasso Image loader Library 将受密码保护的图像加载到 imageview 中。
下面是Authenticator的代码:
private Bitmap download_Image(String url) {
Bitmap bmp = null;
try {
URL ulrn = new URL(url);
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(imagePassword, "mypass".toCharArray());
}
});
HttpURLConnection con = (HttpURLConnection) ulrn.openConnection();
InputStream is = con.getInputStream();
bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
return bmp;
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
【问题讨论】:
-
如何使用身份验证器?你能给我们看看吗?你如何将密码传递给url?
标签: android