I'm trying to send parameters with POST from Ext JS to a Spring application. Here is the my Controller:

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

And here the Ext JS snippet that I'm using to send those parameter:

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

But if I send json data unloadData as body data

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

and change my Controller like this:

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

everything works fine. Why doesn't works first case?

有帮助吗?

解决方案

The reason is by default, if you POST your data, the data will be wrapped in request body, and you got content-type: application/x-www-form-urlencoded

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top