![](/img/trans.png)
[英]Spring Boot - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
[英]Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
@PostMapping public UserResponse createUser(@RequestBody UserRequest userDetail) {
UserResponse returnValue = new UserResponse();
UserDto userDto = new UserDto();
BeanUtils.copyProperties(userDetail, userDto);
UserDto storedData = userService.createUser(userDto);
BeanUtils.copyProperties(storedData, returnValue);
return returnValue;
}
這是我收到此錯誤的代碼
{
"timestamp": "2020-05-13T12:24:04.866+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "/users"
}
我嘗試了很多不同的方法仍然沒有得到解決方案這是來自 postman 的圖像來自 postman的圖像
那是因為您的服務僅接受 application/json 內容類型。 如果您想接受 application/x-www-form-urlencoded 您可以在 @PostMapping 注釋中添加 consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
下面是接受 application/json 並給出 application/json 響應的服務示例。
@PostMapping(path = "/v1/agent/create", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseWrapperDto createAgent(@RequestBody ApiRequestWrapperDto request) throws Exception {
return this.agentManagementApiHandler.createAgent(request);
}
希望這能解決您的問題。
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.