繁体   English   中英

使用POST方法的Spring和ExtJS“错误请求”

[英]Spring and ExtJS “Bad Request” with POST method

我正在尝试将来自Ext JS的POST参数发送到Spring应用程序。 这是我的控制器:

@RequestMapping(value = "/unloadCatalog", method = RequestMethod.POST)
public void unloadMappingCatalog(@RequestParam(required = true) String jsonString,
                                 HttpServletRequest request, HttpServletResponse response)
{

这里是我用来发送这些参数的Ext JS片段:

var unloadData = Ext.encode(listObjects);
Ext.Ajax.request({
    url:'content/unloadCatalog',
    method: 'POST',
    params:{
        jsonString: unloadData
    },
    success: function(response, opts){
        // do something
    }
});

但是如果我发送json数据unloadData作为正文数据

Ext.Ajax.request({
    url:'content/unloadCatalog',
    method: 'POST',
    jsonData: unloadData,
    success: function(response, opts){
        // do something
    }
});

并像这样更改我的控制器:

@RequestMapping(value = "/unloadCatalog", method = RequestMethod.POST)
public void unloadMappingCatalog(@RequestBody String jsonString,
                               HttpServletRequest request, HttpServletResponse response)
{

一切正常。 为什么第一种情况不起作用?

原因是默认情况下,如果您发布数据,数据将被包装在请求正文中,并且您获得了内容类型: application/x-www-form-urlencoded

暂无
暂无

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

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