How can I send Authorization
header using Volley library in Android for GET
method?
This is my request code:
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, url,
null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Response", response.toString());
pd.dismiss();
Toast.makeText(MainActivity.this, "" + response.toString(), Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Error", "Error: " + error.getMessage());
Toast.makeText(MainActivity.this, "" + error.getMessage(), Toast.LENGTH_SHORT).show();
pd.dismiss();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "2e96e0a4ff05ba86dc8f778ac49a8dc0");
return headers;
}
};