简体   繁体   English

Spring Web MVC:HTTP DELETE不再有请求体

[英]Spring Web MVC: no request body possible for HTTP DELETE anymore

I have a question for the developers of Spring Web MVC. 我对Spring Web MVC的开发人员提出了一个问题。

In a nutshell: previously it was possible to send a request body in an HTTP DELETE message, but now it is not possible anymore. 简而言之:之前可以在HTTP DELETE消息中发送请求正文,但现在又不可能了。 Why? 为什么?

In detail: 详细:

We are using spring-webmvc-4.2.4.RELEASE . 我们使用的是spring-webmvc-4.2.4.RELEASE

@RestController
public class Controller {

    @RequestMapping(value = "/{pathVariable}/deleteAnything", method = RequestMethod.DELETE)
    public ResponseEntity<?> deleteAnything(@PathVariable String pathVariable,
        @Valid @RequestBody Set<Pojo> pojoSet) {
        ...

We send 我们发送

DELETE /anything/deleteAnything HTTP/1.1
Content-Type: application/json
Host: example.com

[ {
  "any field" : "Any value"
} ]

and get the exception 并得到例外

m.m.a.RequestResponseBodyMethodProcessor : Read [java.util.Set<packagename.Pojo>] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@333825a3]
.w.s.m.m.a.ServletInvocableHandlerMethod : Error resolving argument [1] [type=java.util.Set]
HandlerMethod details: 
Controller [packagename.Controller]
Method [public org.springframework.http.ResponseEntity<?> packagename.Controller.deleteAnything(java.lang.String,java.util.Set<packagename.Pojo>)]


org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public org.springframework.http.ResponseEntity<?> packagename.Controller.deleteAnything(java.lang.String,java.util.Set<packagename.Pojo>)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:151)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:125)
    ...

It seems that the request body has been removed. 似乎请求正文已被删除。

If we use HTTP POST instead of HTTP DELETE everywhere, it works fine. 如果我们在任何地方使用HTTP POST而不是HTTP DELETE,它可以正常工作。

Previously it worked fine (sorry that I cannot specify previously because our dependencies are very complicated. If it helps you, I can post an old build.gradle ). 以前它工作正常(抱歉我之前无法指定,因为我们的依赖项非常复杂。如果它对您有帮助,我可以发布一个旧的build.gradle )。

Why is it not possible anymore? 为什么不再可能了?

You probably should redesign your API, as payloads within DELETE requests should be ignored. 您可能应该重新设计API,因为忽略DELETE请求中的有效负载。

From http://tools.ietf.org/html/rfc7231#section-4.3.5 : 来自http://tools.ietf.org/html/rfc7231#section-4.3.5

A payload within a DELETE request message has no defined semantics. DELETE请求消息中的有效负载没有定义的语义。

From https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3 : 来自https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3

If the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request. 如果请求方法不包含实体主体的定义语义,则在处理请求时应该忽略消息主体。

It seems to be a problem with zuul. 这似乎与zuul有关。 Without zuul it works. 没有zuul它的工作原理。 Spring has nothing to do with it. Spring与它无关。

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

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