I have a curl command that works perfectly curl --request POST --user xyz@mail.com:password http://localhost:8080/api/uploadmydata -d 'param1=300'
But I am unable to do the same thing with volley. My current code is:
public static void tryUploading(final Activity activity){
StringRequest stringRequest = new StringRequest(Request.Method.POST, BackendConnection.uploadDataUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//textPrompt.setText("Wrong User name or Password");
}
}){
@Override
public Map<String, String> getHeaders() {
Map<String, String> params = new HashMap<String, String>();
params.put(
"Authorization",
String.format("Basic %s", Base64.encodeToString(
String.format("%s:%s", "xyz@mail.com", "password").getBytes(), Base64.DEFAULT)));
params.put("param1", 300);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(activity);
requestQueue.add(stringRequest);
}
I am using spring boot as server. In the server above code triggers verification of username and password but fails to reach the intended url later. How to add both user credentails and parameters in volley request like we do in curl --user and -d?