Http status 415 Unsupported Media Type
程序员文章站
2022-07-12 20:29:06
...
What is 415 ?
-
HTTP 415 Unsupported Media Type
The client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.
Let’s look at the broswer ?
How to resolve 405 problem when using ajax post @ResponseBody return json data ?
if you use Spring 4.x jar,please following me(Maven Repository-Spring 4.x.jar)
-
add related jar package
spring-webmvc.x.x.jar
jackson-databind.jar
jackson-core.jar
jackson-annotations.jar In Spring Configuration file,add following code
<bean class="org.springframework.web.servlet.mvc.
annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.
MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
- In ajax , set contentType : ‘application/json;charse=UTF-8’
var data = {"name":"jsutin","age":18};
$.ajax({
url : "/ASW/login.html",
type : "POST",
data : JSON.stringify(data),
dataType: 'json',
contentType:'application/json;charset=UTF-8',
success : function(result) {
console.log(result);
}
});
- In server ,using @RequestBody anotation receive json data,and using @ResponseBody anotation response json to jsp page
@RequestMapping(value = "/login",method = RequestMethod.POST)
public @ResponseBody User login(@RequestBody User user){
system.out.println(user.getName);
system.out.println(user.getAge);
}
推荐阅读
-
Python requests post 请求报错:415 Unsupported Media Type
-
Http status 415 Unsupported Media Type
-
Unsupported Media Type Http请求415错误
-
PostMan报415Unsupported Media Type
-
org.springframework.web.HttpMediaTypeNotSupportedException: Unsupported Media Type, status=415
-
Postman报错Unsupported Media Type
-
org.springframework.web.HttpMediaTypeNotSupportedException: Unsupported Media Type, status=415
-
SpringMVC 报错HTTP Status 500 - No converter found for return value of type解决方案
-
请求接口时返回 http 415 unsupported media type错误解决方法
-
spring mvc 下,ajax调用后台controller方法时报415 (Unsupported Media Type)错误