SpringMVC is not recognizing request body parameters if using PUT

后端 未结 4 1123
我在风中等你
我在风中等你 2020-12-04 16:50

Maybe this is supposed to not work, but at least I\'d like to understand why then. I am passing a simple val=somevalue in the PUT body but spring sends back a <

4条回答
  •  没有蜡笔的小新
    2020-12-04 17:34

    This, as suggest above, seems to be a bug in spring/servlet API. In reality PUT requests are supposed to work on Request Body (or payload) and not on Request Parameters. In that sense, servlet API & spring's handling is correct.

    Having said that, a better and much easier workaround is to pass no data element from your javascript/jQuery call and pass your parameters as part of the url itself. meaning, set parameters in the url field the way you would do in a GET call.

    $.ajax({
                url: "yoururl" + "?param1=param2Val&..",
                type: "PUT",
                data: "",
                success: function(response) {
                    // ....
                }
         });
    

    now this works for simple parameters, i guess, will not work for complex JSON types. Hope this helps.

提交回复
热议问题