Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top