'Is there any way to set the headers when making a synchronous Volley call?
Is there any way to set the headers when making a synchronous Volley call? Here is my code:
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, localUri, postData, future, future);
VolleySingleton.getmInstance(context).addToRequestQueue(request);
JSONObject response = future.get();
I see how to do it with a listener, but not
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, localUri, postData, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse: ");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "post.onErrorResponse: " + error.getMessage() );
}
}) {
//here is where we pass the access tokens
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return getGlobalHeaders();
}
@Override
public String getBodyContentType() {
Log.d(TAG, "getBodyContentType: " + super.getBodyContentType());
return "application/json";
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
