I try to make call request with Volley library. I want to set headers, but I'm getting java.lang.UnsupportedOperationException. Do you know why , and how can I solve this problem ?
public void getAccountInfo() {
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
String url = "http://demo.gopos.pl/oauth/token";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
Log.e(TAG, "onResponse SUCCES!!" + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "That didn't work!");
}
}) {
@Override
public Map<String,String> getHeaders()throws AuthFailureError {
Map<String,String> params = super.getHeaders();
if(params==null)params = new HashMap<>();
params.put("username","username");
params.put("password","password");
return params;
}
};
queue.add(stringRequest);
}