问题
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);
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?
Alternatively, is there a way to set something like followRedirects = false (and intercept the redirect in this way)?
回答1:
With OkHttp:
public static void setFollowRedirects (boolean auto)
public OkHttpClient setFollowProtocolRedirects(boolean followProtocolRedirects)
With HttpURLConnection:
public static void setFollowRedirects (boolean auto)
public void setInstanceFollowRedirects (boolean followRedirects)
See discussion here.
来源:https://stackoverflow.com/questions/18218726/square-retrofit-client-how-to-enable-disable-followredirects-how-to-intercept