Skip to content

Instantly share code, notes, and snippets.

@fcaldarelli
Created September 10, 2015 23:58
Show Gist options
  • Save fcaldarelli/ad1118e5d8ab0661ba36 to your computer and use it in GitHub Desktop.
Save fcaldarelli/ad1118e5d8ab0661ba36 to your computer and use it in GitHub Desktop.
Custom header in HTTP Request with Volley
public void requestWithSomeHttpHeaders() {
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://www.somewebsite.com";
StringRequest postRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
// response
Log.d("Response", response);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("ERROR","error => "+error.toString());
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("User-Agent", "Nintendo Gameboy");
params.put("Accept-Language", "fr");
return params;
}
};
queue.add(postRequest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment