-
-
Save alitamoor65/5b46b4af3974523b3a2c99904e48c814 to your computer and use it in GitHub Desktop.
Example of Volley GET and POST requests with parameters and headers
This file contains hidden or 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
RequestQueue queue = Volley.newRequestQueue(context); | |
//for POST requests, only the following line should be changed to | |
StringRequest sr = new StringRequest(Request.Method.GET, "http://headers.jsontest.com/", | |
new Response.Listener<String>() { | |
@Override | |
public void onResponse(String response) { | |
Log.e("HttpClient", "success! response: " + response.toString()); | |
} | |
}, | |
new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
Log.e("HttpClient", "error: " + error.toString()); | |
} | |
}) | |
{ | |
@Override | |
protected Map<String,String> getParams(){ | |
Map<String,String> params = new HashMap<String, String>(); | |
params.put("user","YOUR USERNAME"); | |
params.put("pass","YOUR PASSWORD"); | |
return params; | |
} | |
@Override | |
public Map<String, String> getHeaders() throws AuthFailureError { | |
Map<String,String> params = new HashMap<String, String>(); | |
params.put("Content-Type","application/x-www-form-urlencoded"); | |
return params; | |
} | |
}; | |
queue.add(sr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment