Created
September 10, 2015 23:58
-
-
Save fcaldarelli/ad1118e5d8ab0661ba36 to your computer and use it in GitHub Desktop.
Custom header in HTTP Request with Volley
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 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