Passing data in the body of a DELETE request

后端 未结 5 1871
后悔当初
后悔当初 2020-12-14 17:05

I have two Spring MVC controller methods. Both receive the same data in the request body (in the format of an HTLM POST form: version=3&name=product1&

5条回答
  •  醉话见心
    2020-12-14 17:49

    The problem is not a Spring problem, but a Tomcat problem.

    By default, Tomcat will only parse arguments that are in the form style, when the HTTP method is POST (at least for version 7.0.54 that I checked but it's probably the same for all Tomcat 7 versions).

    In order to be able to handle DELETE methods as well you need to set the parseBodyMethods attribute of the Tomcat Connector. The connector configuration is done in server.xml.

    Your updated connector would most likely look like:

    
    

    Here is documentation page for configuring Tomcat connectors.

    Once you setup Tomcat to parse the parameters, Spring will work just fine (although in your case you will probably need to remove @RequestBody from the controller method)

提交回复
热议问题