【问题标题】:Get redirected URL from Picasso从 Picasso 获取重定向 URL
【发布时间】:2015-07-09 06:39:54
【问题描述】:

我正在使用以下代码获取我的图像:

Picasso.with(mContext)                              
    .load(myImage.getUrl())
    .fetch();

myImage.getUrl() 从我的服务器返回一个 URL,该 URL 将重定向到另一台服务器上托管的实际图像。有没有办法捕获我的服务器返回给毕加索的 URL?我知道我可以在.fetch() 中使用Callback,但这就是我所知道的。我也在使用 OkHttp。

【问题讨论】:

    标签: android picasso


    【解决方案1】:

    OkHttp 允许您不自动跟踪重定向

    OkHttpClient client = new OkHttpClient();
    client.setFollowRedirects(false);
    

    您可以阅读响应,获取重定向 URL,然后手动将其转发给 Picasso。

    编辑:

    Interceptors 也是可行的:

    OkHttpClient client = new OkHttpClient();
    client.interceptors().add(new Interceptor() {
      @Override
      public Response intercept(Chain chain) throws IOException {
        // process response here
        return response;
      }
    });
    

    【讨论】:

    • 我有点困惑。我如何将它与毕加索一起使用?
    • 这根本不是答案。
    • 这不能回答问题
    【解决方案2】:

    我通过这段代码修复了它。

    val downloader = OkHttp3Downloader(context)
    Picasso.Builder(context).downloader(downloader).build()
    

    查看详情。 https://github.com/square/picasso/issues/463

    【讨论】:

      【解决方案3】:

      添加okhttp依赖

      compile 'com.squareup.okhttp:okhttp:2.5.0'
      

      试试这段代码

        Picasso.Builder builder = new Picasso.Builder(context);
        builder.downloader(new OkHttpDownloader(context));
        builder.build()
       .load(path.trim())
       .into(imageView);
      

      这段代码对我有用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-24
        • 1970-01-01
        • 1970-01-01
        • 2017-02-02
        • 2021-03-28
        • 2013-06-06
        • 2019-08-29
        • 1970-01-01
        相关资源
        最近更新 更多