-
-
Save nguyenngan/308d08fcf3d7eb0c7a4278e5d1d7e6bb 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
it is not working for me. Please help me