Volley JsonObjectRequest Put is not working

850 Views Asked by At

I am making JsonObjectRequest with Put method but it is not working and getting "{"detail":"Method \"GET\" not allowed."}" error message.

It is working fine on Postman. See attached screenshots for more information. enter image description here

I didn't modify JsonObjectRequest. I copy this code from google sample code from here "http://developer.android.com/training/volley/request.html".

I don't think this could be a bug in Volley. Please go through my code and let me know what I am doing wrong.

JsonObjectRequest jsObjRequest = new JsonObjectRequest
            (Request.Method.PUT, url, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    hideDialog();
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    hideDialog();

                }
            })

    {
        @Override
        public Map getHeaders() throws AuthFailureError {
            Map headers = new HashMap();
            headers.put("Authorization", "Token " + dm.readString("auth_token"));
            return headers;
        }
    };

AppController.getInstance().addToRequestQueue(jsObjRequest);

Edit: I know in the screenshot it shows 400 bad request. It is because i need to pass 2 params ie {"dg_id":"80","delivery_ids":["90936"]}. With this params also i am getting the same error in Volley.

Sample auth_token Value: MTIzNDU2NzIzNDM6ZGVsaXZlcnlndXk=

Sample Body value: {"dg_id":"80","delivery_ids":["90936"]}

1

There are 1 best solutions below

0
On

Add "/" at end of DELETE, PUT interface url,do check out the following snippet.

If a client issues a GET request to "/testdir/" (i.e., at the directory).......It is interesting to take note that if a client issue a GET request to "/testdir" (without specifying the directory path "/"), the server returns a "301 Move Permanently" with a new "Location" of "/testdir/", as follows.