簡體   English   中英

Rest API:發布 API 投擲 400 錯誤請求

[英]Rest API : Post API Throwing 400 Bad request

用例 -

我有一個帖子 API,它應該使用 Content-Type = x-www-form-urlencoded。 創建單獨的啟動項目並實施 POST API 時,我在我的控制器中獲取表單數據(使用郵遞員對其進行測試),但是當我將相同的代碼集成到我的項目(即 Spring MVC 項目)中時,每當我測試它時,它總是給我 400響應中的錯誤請求。

  @RequestMapping(value = "/registration", method = RequestMethod.POST,consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public void marketplaceRegistration(@RequestBody MultiValueMap<String, String> formData, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {
    LOGGER.info("\nIn registration method: TOKEN RECIEVED IS "+formData.getFirst("token"));}

這是我將接收請求的方法。 我使用了@RequestBody、@RequestParam 這兩個注釋,並且都可以在 spring 啟動應用程序中正常工作,但是當我集成時,它會拋出 400 Bad request。

唯一的區別是我們有一個來自 apache 的 WsFilter。 不知道出了什么問題,但如果有人能提供幫助那就太好了。

顯然,在我的項目中,我將 Post API 與 ContentType 集成為 x-www-form-urlencoded,過濾器正在讀取請求,因此 urlencoded 表單數據的請求正文丟失了。 刪除過濾器后,我的請求將通過 controller,我能夠獲得 200 響應。

不幸的是不能在這里發布過濾器邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM