我需要从需要标头身份验证的 api 中检索图像。我正在为毕加索指定一个自定义下载器,但图像永远不会显示。我是否正确覆盖了 openConnection 方法?
Picasso.Builder builder = new Picasso.Builder(getApplicationContext());
builder.downloader(new OkHttpDownloader(getApplicationContext()) {
@Override
protected HttpURLConnection openConnection(Uri uri) throws IOException {
HttpURLConnection connection = super.openConnection(uri);
connection.setRequestMethod("GET");
connection.setRequestProperty("X_AUTH_TOKEN", authToken);
return connection;
}
});
Picasso picasso = builder.build();
picasso.with(getApplicationContext()).load("http://example.com/api/users/pic/14").into(ivProfilePic);