Created
March 14, 2018 09:39
-
-
Save Ray33/97ff7c72226458847b8cc99ca16e38ba to your computer and use it in GitHub Desktop.
Android Get with redirect support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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