Spring和ExtJS“400 Bad Request”与PUT但不是POST [英] Spring and ExtJS "400 Bad Request" with PUT but not with POST

查看:571
本文介绍了Spring和ExtJS“400 Bad Request”与PUT但不是POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PUT从JavaScript发送参数到Spring应用程序。这是Spring控制器中的@RequestMapping:

I'm trying to send parameters with PUT from JavaScript to a Spring application. Here is the @RequestMapping in a Spring Controller:

@RequestMapping(value = "toggle-paid-action", method = RequestMethod.PUT)
@ResponseBody
public final String togglePaid(@RequestParam final int year, 
    @RequestParam final String docType, @RequestParam final int number) {

这里是应该发送这些参数的JavaScript代码段。

And here the JavaScript snippet that is supposed to send those parameters.

Ext.Ajax.request({
    params: {year: year, docType: docType, number: number},
    url: 'toggle-paid-action',
    method: 'PUT',

然而,我每次都收到一个400错误请求描述客户端发送的请求在语法上不正确()。

However, I get a "400 Bad Request" every time with description "The request sent by the client was syntactically incorrect ()".

如果我使用Firebug检查,有一个PUT选项卡,其中包含所有参数,参数是正确拼写,因为如果我从PUT切换到POST两边都有效。

If I check with Firebug, there is a PUT tab with all my parameters, and the parameters are correctly spelled since if I switch from PUT to POST on both sides everything works.

我在想什么可能是问题,PUT是否限于@PathVariable参数,还是可以发送类似POST的参数?

I was wondering what could be the problem, is PUT limited to @PathVariable parameters, or it can send also POST-like parameters?

推荐答案

您不能使用请求方法PUT来传递参数,因为servlet API中有一个限制。在其他情况下(如Spring MVC Databinding),您只能使用PUT方法实现一个安静的服务,传递数据作为请求正文,否则PUT将无法正常工作。
请参阅 SpringMVC无法识别请求体参数如果使用PUT

I suppose you can't pass parameters to spring using request method PUT as there is a restriction in the servlet API. You can only work with PUT methods implementing a restful service, passing data as the request body, in other cases (like Spring MVC Databinding) PUT won't work. see SpringMVC is not recognizing request body parameters if using PUT

JIRA:
https://jira.springsource.org/browse/SPR-7414

这篇关于Spring和ExtJS“400 Bad Request”与PUT但不是POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆