从毕加索获取重定向的URL [英] Get redirected URL from Picasso

查看:66
本文介绍了从毕加索获取重定向的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm fetching my images using the following code:

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

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

myImage.getUrl() returns a URL from my server, which will redirect to the actual image hosted on another server. Is there a way to catch the URL my server returns to Picasso? I know I can use a Callback in .fetch(), but that's all I know. I'm using OkHttp as well.

推荐答案

OkHttp允许您不自动遵循重定向:

OkHttp allows you not to follow redirects automatically:

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

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

You can read the response, get the redirect URL and then forward it manually to Picasso.

Interceptor也是可行的:

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

这篇关于从毕加索获取重定向的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆