简体   繁体   English

齐射JsonObjectRequest放置不起作用

[英]Volley JsonObjectRequest Put is not working

I am making JsonObjectRequest with Put method but it is not working and getting "{"detail":"Method \\"GET\\" not allowed."}" error message. 我正在使用Put方法制作JsonObjectRequest,但无法正常工作,并收到“ {“ detail”:“ Method \\” GET \\“不允许。”}“错误消息。

It is working fine on Postman. 在Postman上运行正常。 See attached screenshots for more information. 有关更多信息,请参见所附的屏幕截图。 在此处输入图片说明

I didn't modify JsonObjectRequest. 我没有修改JsonObjectRequest。 I copy this code from google sample code from here " http://developer.android.com/training/volley/request.html ". 我从这里的“ http://developer.android.com/training/volley/request.html ”中复制了Google示例代码中的代码。

I don't think this could be a bug in Volley. 我认为这不是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); 。AppController.getInstance()addToRequestQueue(jsObjRequest);

Edit: I know in the screenshot it shows 400 bad request. 编辑:我知道在屏幕快照中它显示400错误的请求。 It is because i need to pass 2 params ie {"dg_id":"80","delivery_ids":["90936"]}. 这是因为我需要传递2个参数,即{“ dg_id”:“ 80”,“ delivery_ids”:[“ 90936”]}。 With this params also i am getting the same error in Volley. 有了这种参数,我在排球上也遇到了同样的错误。

Sample auth_token Value: MTIzNDU2NzIzNDM6ZGVsaXZlcnlndXk= 样本auth_token值:MTIzNDU2NzIzNDM6ZGVsaXZlcnlndXk =

Sample Body value: {"dg_id":"80","delivery_ids":["90936"]} 样本正文值:{“ dg_id”:“ 80”,“ delivery_ids”:[“ 90936”]}

Add "/" at end of DELETE, PUT interface url,do check out the following snippet. 在DELETE,PUT接口网址的末尾添加“ /”,请检查以下代码段。

If a client issues a GET request to "/testdir/" (ie, 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. 如果客户端向“ / testdir /”发出GET请求(即,在目录中).......有趣的是,如果客户端向“ / testdir”发出了GET请求(未指定目录路径“ /”),服务器将返回“ 301永久移动”,新的“位置”为“ / testdir /”,如下所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM