我收到的帖子有问题。我有以下端点:
@RequestMapping(value = "/payment", method = POST)
public void saveOrder(@RequestBody PaymentDto paymentDto) throws RequiredFieldException, IOException, MessagingException {
//do something
}
现在,当有人通过此 URL 向我发送 POST 时,我会收到以下响应:
{"errorMessage":"Unsupported Media Type",
"errorId":"906f5dc8-0b79-4f91-9eaa-a252e8d5ac76",
"errorDetails":
{"message":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"exception":"org.springframework.web.HttpMediaTypeNotSupportedException",
"errors":null
}}
我该如何解决这个问题?发送时我无法更改内容类型 header 。它是从我无法控制的服务器发送的。
最佳答案
如果 Content Type 是 application/json 或 application/xml 使用 @RequestBody 注解,如果是 application/x-www-form-urlencoded 使用 @ModelAttribute
关于java - Spring 中的内容类型问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39385960/