2

我需要从需要标头身份验证的 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); 
4

1 回答 1

9

不要使用Picasso.with(). 这是一个初始化默认Picasso实例的静态方法。

您正在使用自定义下载器构建您的实例,但您没有使用它。

只需picasso.load()在构建实例后直接调用。

于 2014-07-11T22:59:22.970 回答