簡體   English   中英

使用 Postman 和 Soapui 我在到達 Spring 引導端點時得到 400,但 Swagger 沒有問題

[英]Using Postman and Soapui I get a 400 when hitting a Spring Boot endpoint, but Swagger has no problem

端點位於具有此簽名的 RestController 中:

@PostMapping(value = "/unclaim")
@Operation(summary = "Unclaim Tasks ")
public BaseResponse<String> claimTasks(
        @RequestParam(required = true, name = "taskIds") Long taskIds[]
        ) 
{

如果我使用 Soap ui 到正確的 URL (我知道我做對了,b/c 如果我 append 給它另一個字符,我得到一個有效載荷:4)

{
taskIds: [ 444, 34, 55 ]
}

在 SoapUI 和 Postman 中執行此操作都給出 400 秒且沒有解釋:

HTTP/1.1 400 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Set-Cookie: JSESSIONID=C18701F799961FEECF967457574EB914; 路徑=/tlmapi; HttpOnly 內容長度:0 日期:2022 年 9 月 2 日星期五 16:11:44 GMT 連接:關閉

但是轉到此 controller 的 swagger-ui.html 頁面,我可以構建一個有效的請求:

在此處輸入圖像描述

在此處輸入圖像描述

那么有什么區別呢? 或者有沒有辦法查看 swagger 正在發送的有效負載?

結果我不小心在列表中使用了@RequestParam 注釋,而不是@RequestBody。 此外,該參數是必需的,因此 spring 拒絕了它並忽略了來自 SoapUI 和 Postman 的我的 Json 有效負載。

希望這可以幫助某人不要浪費幾個小時......

暫無
暫無

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

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