簡體   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