我正在嘗試打電話POST。我的身體只有一個參數(shù),所以我想簡單地使用@RequestParam.代碼: @RequestMapping(value = "/call", method = RequestMethod.POST) @ResponseBody public void doStuff(@RequestParam List<Integer> nums, HttpServletResponse response) {通話x-www-form-urlencoded效果很好-卷曲 -X POST https://localhost:9002/call-H '授權(quán):承載 d1436121-25f7-4162-b0d4-7699d4acf147'-H '內(nèi)容類型:application/x-www-form-urlencoded'-H '主機:localhost:9002'-d nums=0%2C1% 2C3但使用 JSON 進行同樣的調(diào)用會失敗。代碼: @RequestMapping(value = "/call", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public void doStuff(@RequestParam List<Integer> nums, HttpServletResponse response) {呼叫application/json失敗-curl -X POST https://localhost:9002/call-H '授權(quán):承載 d1436121-25f7-4162-b0d4-699d4acf147'-H '內(nèi)容類型:application/json'-H '主機:localhost:9002'- d '{ "nums":[0,1,3] }'錯誤:{ "errors": [ { "message": "抱歉,發(fā)生錯誤。", "type": "MissingServletRequestParameterError" } ] }為什么它接受x-www-form-urlencoded卻又拒絕JSON。
POST 調(diào)用接受 x-www-form-urlencoded 但拒絕 JSON
慕田峪4524236
2023-07-19 16:36:18