Skip to content

Instantly share code, notes, and snippets.

@Ray33
Created March 14, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ray33/97ff7c72226458847b8cc99ca16e38ba to your computer and use it in GitHub Desktop.
Save Ray33/97ff7c72226458847b8cc99ca16e38ba to your computer and use it in GitHub Desktop.
Android Get with redirect support
public static void httpGetWithRedirectSupport(final Context context, String url){
Volley.newRequestQueue(context).add(new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
// Do nothing
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
if (volleyError.networkResponse != null && (volleyError.networkResponse.statusCode == 302 || volleyError.networkResponse.statusCode == 301)) {
if (volleyError.networkResponse.headers.containsKey("Location")) {
httpGetWithRedirectSupport(context, volleyError.networkResponse.headers.get("Location"));
}
}
}
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment