307 Temporary Redirect: What It Is and How to Fix It- Android
I was stuck when i found this. Dont step back guys!Here is a wonderful solution i have. A 307 Temporary Redirect message is an HTTP response status code
indicating that the requested resource has been temporarily moved to another URI
, as indicated by the special Location
header returned within the response. The 307 Temporary Redirect
code was added to the HTTP standard in HTTP 1.1, as detailed in the RFC2616 specification document that establishes the standards for that version of HTTP. As indicated in the RFC, “since the redirection may be altered on occasion, the client should continue to use the Request-URI for future requests.”
You can create an extra interceptor to handle 307
private static class RedirectInterceptor implements Interceptor {@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(chain.request());
if (response.code() == 307) {
request = request.newBuilder()
.url(response.header("Location"))
.build();
response = chain.proceed(request); }
return response;
}
and add the RedirectInterceptor to your okHttpClient(okhttp2 for example)
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(new RedirectInterceptor());
okHttpClient.setFollowRedirects(false);
Here u go guys!! peace out.