2017-09-16 45 views
0

我得到HTTP错误422,同时使用volley进行DELETE请求。但是,当我向邮递员提出要求时,我能够成功回应。另外,当我尝试使用HTTPConnection时,又遇到了同样的错误。用参数使用Volley删除

这里是我的凌空请求的代码

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.DELETE, SERVER_URL, 
postPropertyJSONObject, responseListener, errorListener); 
+0

https://stackoverflow.com/questions/33553559/delete-request-with-header-and-parametes-volley/或使用get或交 –

回答

2

可以参考https://github.com/ngocchung/DeleteRequest长期的解决方案,因为它从文件看,但我没有测试过这一点。一个快速工作arrount是,作为post发出请求,然后用DELETE覆盖头部X-HTTP-Method-Override。

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST, SERVER_URL,postPropertyJSONObject, responseListener, errorListener); 

然后添加页眉这样

@Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 
      Map<String, String> headers = new HashMap<String, String>(); 
      headers.put("X-HTTP-Method-Override", "DELETE"); 
      headers.put("Accept", "application/json"); 
      headers.put("Content-Type", "application/json"); 

      return headers; 
     } 
+0

感谢这种覆盖方法为我工作。 –