-
-
Save TheCrazyMax/fb07036a9a14c2dbf210597c69994a2f to your computer and use it in GitHub Desktop.
Simple Post Request with basic auth, using android Volley library
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
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { | |
@Override | |
public void onResponse(String s) { | |
///handle response from service | |
}, new ErrorResponse() { | |
@Override | |
public void onErrorResponse(VolleyError volleyError) { | |
//handle error response | |
} | |
}) { | |
@Override | |
protected Map<String, String> getParams() throws AuthFailureError { | |
Map<String, String> params = new HashMap<String, String>(); | |
//add params <key,value> | |
return params; | |
} | |
@Override | |
public Map<String, String> getHeaders() throws AuthFailureError { | |
Map<String,String> headers = Constants.getHeaders(context); | |
// add headers <key,value> | |
String credentials = USERNAME+":"+PASSWORD; | |
String auth = "Basic " | |
+ Base64.encodeToString(credentials.getBytes(), | |
Base64.NO_WRAP); | |
headers.put("Authorization", auth); | |
return headers; | |
} | |
}; | |
mQueue.add(request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment