广场改造客户:如何启用/禁用followRedirects?如何拦截重定向URL? [英] Square Retrofit Client: How to enable/disable followRedirects? How to intercept redirect URL?
问题描述
我使用的是广场的改造Client向从Android应用简单的要求。像这样:
I'm using Square's Retrofit Client to make simple requests from an Android App. Like so:
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(Configurations.getInstance().plistMap.get("PTBaseURL"))
.setRequestHeaders(new RequestHeaders() {
@Override
public List<Header> get() {
List<Header> headers = new ArrayList<Header>();
Header authHeader = new Header("Authorization", authType + " " + UserManager.getInstance().currentUser.token);
headers.add(authHeader);
}
return headers;
}
})
.build();
this.service = restAdapter.create(ClientInterface.class);
一个端点重定向到一个不同的URL(S3)。对于一个原因,这个问题并不重要重定向请求失败,因此我的 callback.failure(错误)
方法被调用。我需要能够在某些时候,preferable在来访问和修改重定向URL或要求callback.failure()
。我怎样才能做到这一点?
One endpoint redirects to a different URL (s3). For an reason not important to this question the redirect request is failing and thus my callback.failure(error)
method is being called. I need to be able to access and modify the redirect URL or request at some point, preferable in callback.failure()
. How can I do this?
另外,有一种方法来设置类似 followRedirects = FALSE
(和拦截以这种方式重定向)?
Alternatively, is there a way to set something like followRedirects = false
(and intercept the redirect in this way)?
推荐答案
通过 OkHttp
:
public static void setFollowRedirects (boolean auto)
public OkHttpClient setFollowProtocolRedirects(boolean followProtocolRedirects)
使用 HttpURLConnection类
:
public static void setFollowRedirects (boolean auto)
public void setInstanceFollowRedirects (boolean followRedirects)
这里见讨论。
See discussion here.
这篇关于广场改造客户:如何启用/禁用followRedirects?如何拦截重定向URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!