I'm using this simple code :
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
delegate.postNotificationSucced();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Log.d(TAG, ""+error.getMessage()+","+error.toString());
delegate.postNotificationFailed((APIErrors) error);
}
}){
@Override
public Map<String, String> getParams() throws AuthFailureError {
Map<String,String> headers = new HashMap<String, String>();
headers.put("Content-Type","application/x-www-form-urlencoded");
headers.put("state", Boolean.toString(isChecked));
return headers;
}
@Override
protected VolleyError parseNetworkError(VolleyError volleyError){
APIErrors error = null;
if(volleyError.networkResponse != null && volleyError.networkResponse.data != null){
error = new APIErrors(new String(volleyError.networkResponse.data));
}
return error;
}
};
When I use the Request.Method.GET
or POST
instead of PUT
, the getParams()
method is called but not with the PUT
method.
My problem is that my API requires a PUT
method.
How can I pass my parameters using the PUT
method.
Edit :
With the PUT
method the getHeaders()
method is called, so can I pass my arguments through it ?
Solution :
In my case I solved the problem changing my JsonObjecRequest to StringRequest like suggested by @ishmaelMakitla. And now I pass inside getParams()
.
I noticed that you are not using the response object for anything - so perhaps change the request from JsonObjectRequest to a StringRequest - remember that you then need to change Response.Listener() to Response.Listener() and the onResponse(JSONObject response) to onResponse(String response)....shout if you need further help. I hope this leads to some workable solution.
The reason is that with JsonObjectRequest, parameters must be pass through the third parameters of the constructor
jsonRequest - A JSONObject to post with the request. Null is allowed and indicates no parameters will be posted along with request.
you can read the doc for more informations.
JsonObjectRequest
to aStringRequest
- remember that you then need to changeResponse.Listener<JSONObject>()
toResponse.Listener<String>()
and theonResponse(JSONObject response)
toonResponse(String response)
....shout if you need further help. I hope this leads to some workable solution. – ishmaelMakitla