【发布时间】:2014-05-30 13:13:32
【问题描述】:
我正在编写一个 RESTful API 并尝试使用所有可用的 http 方法,但 PUT 方法有问题。
当我使用 put 方法发送 http 请求时,出现“400 Bad request”错误。 如果我使用 POST 方法,我没有问题。
这是我的 http PUT 请求:
Remote Address:::1:8080
Request URL:http://localhost:8080/adminRight
Request Method:PUT
Status Code:400 Mauvaise Requête
Request Headersview parsed
PUT /adminRight HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 37
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=41D1CCDF94D3150F0FCA3754E347A4AD
Request Payload
typeList=1&id=2&nom=labelViewerAvance
Response Headersview parsed
HTTP/1.1 400 Mauvaise Requête
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 984
Date: Fri, 30 May 2014 12:55:32 GMT
Connection: close
这里是我的 http POST 请求:
Remote Address:::1:8080
Request URL:http://localhost:8080/adminRight
Request Method:POST
Status Code:200 OK
Request Headersview parsed
POST /adminRight HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 37
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=41D1CCDF94D3150F0FCA3754E347A4AD
Request Payload
typeList=1&id=2&nom=labelViewerAvance
Response Headersview parsed
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=utf-8
Content-Length: 2
Date: Fri, 30 May 2014 13:09:03 GMT
PUT 和 POST 语法有什么区别?或者,它是我 web.xml 中的一种特殊配置吗?
提前感谢您的帮助。
使用新信息进行编辑:
我的请求通过这两种方法映射到 java 中:
@RequestMapping(value = "/adminRight",
method = RequestMethod.PUT
)
@ResponseBody
public ResponseEntity<String> updateListRights(@RequestParam(value = "typeList") String typeList,
@RequestParam(value = "id") String idList,
@RequestParam(value = "nom") String nomList)
{
和
@RequestMapping(value = "/adminRight",
method = RequestMethod.POST
)
@ResponseBody
public ResponseEntity<String> addNewListRights(@RequestParam(value = "typeList") String typeList,
@RequestParam(value = "id") String idList,
@RequestParam(value = "nom") String nomList)
{
【问题讨论】:
标签: rest spring-mvc httprequest put