문제

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