【问题标题】:Picasso Custom Downloader Issue毕加索自定义下载器问题
【发布时间】:2014-09-02 03:41:48
【问题描述】:

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

【问题讨论】:

  • 尝试改成connection.setDoOutput(false);
  • @TizianoPiccardi 已测试但无法正常工作

标签: java android httpurlconnection picasso okhttp


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    相关资源
    最近更新 更多