我使用以下代码获取图像:
Picasso.with(mContext)
.load(myImage.getUrl())
.fetch();
myImage.getUrl()
从我的服务器返回一个 URL,该 URL 将重定向到另一台服务器上托管的实际图像。有没有办法捕获我的服务器返回给 Picasso 的 URL?我知道我可以在 .fetch()
中使用 Callback
,但这就是我所知道的。我也在使用 OkHttp。
最佳答案
OkHttp 允许您不自动遵循重定向:
OkHttpClient client = new OkHttpClient();
client.setFollowRedirects(false);
您可以阅读响应,获取重定向 URL,然后手动将其转发给 Picasso。
编辑:
拦截器
也是可行的:
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
// process response here
return response;
}
});
关于android - 从 Picasso 获取重定向 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29952860/