HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported

目錄

1、報錯信息

2、訪問的Controller

3、解決方案


1、報錯信息

由於報錯 提示信息太長,所以只截取了一部分,不影響判斷,原因是因爲數據傳輸格式選擇錯誤。

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:224)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:126)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:166)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)

2、訪問的Controller

@ApiOperation("添加廣告")
@ApiImplicitParam(name = "advertInfoParam",value = "添加廣告" , dataType = "AdvertInfoParam", paramType = "body")
@PostMapping("/advert/insertAdvert")
public CommResponse<?> insertAdvert(@RequestHeader("accessToken") String accessToken,
                                    @RequestBody AdvertInfoParam advertInfoParam) {
     return this.advertInfoServiceFacade.insertAdvert(advertInfoParam);
}

3、解決方案

1、POSTMAN測試工具,原因是因爲數據傳輸格式選擇錯誤。

postman之所以報Unsupported Media Type: Content type 'text/plain;charset=UTF-8' not supported錯誤,是發送數據的格式不正確,需要修改數據的發送方式所匹配的格式。因爲發送的數據是json格式的,而postman默認是text格式,有些會報錯,所以改成選擇json樣式。

2、配置HTTP信息頭管理器,增加消息頭 Content-Type:application/json;charset=UTF-8

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章