问题.springmvc错误.415:Unsupported Media Type
场景是在希望用ajax发post请求,传递一个json对象,在controller中直接使用java对象接收时遇到的,具体错误信息如下:
{
"timestamp": 1500272249207,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "/addSuggestions"
}
原因如错误信息里所说:Content type不支持。将Content type改为:application/json可以解决问题。
本人使用postman模拟的http请求,简单如下:


对应controller处理:
package cn.migu.battle.controller; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import cn.migu.battle.constant.InterfaceConstant;
import cn.migu.battle.model.UserSuggestionModel;
import cn.migu.battle.service.UserSuggestionService;
import cn.migu.battle.utils.JsonResponseForList; /**
*
* @author Administrator
*
*/
@RestController
public class UserSuggestionController { @Autowired
private UserSuggestionService service; @RequestMapping(value = "/addSuggestions",method = {RequestMethod.POST})
public JsonResponseForList addSuggestion(@RequestBody(required = false) UserSuggestionModel model){
if(!service.addSuggestions(model)){
return new JsonResponseForList(InterfaceConstant.STATUS_FAILURE,InterfaceConstant.MESSAGE_FAILURE,null);
}
return new JsonResponseForList(InterfaceConstant.STATUS_SUCCESS,InterfaceConstant.MESSAGE_SUCCESS,null);
}
}
具体解释不再赘述,参考链接:
http://blog.csdn.net/LostSh/article/details/68923874
http://blog.csdn.net/ccc20134/article/details/45094679
问题.springmvc错误.415:Unsupported Media Type的更多相关文章
- springmvc4.3.7中使用RequestBody,传入json参数时,得到错误415 Unsupported Media Type
在新建一个maven的项目的时候,当时并非springboot项目,是通过xml来配置的项目.在项目中DispatcherServlet的配置文件中配置了annotation-driven的, < ...
- SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
一.概述: 本文介绍且记录如何解决在SpringMVC 中遇到415 Unsupported Media Type 的问题,并且顺便介绍Spring MVC的HTTP请求信息转换器HttpMessag ...
- springMVC中使用 RequestBody 及 Ajax POST请求 415 (Unsupported Media Type)
使用POST请求的时候一直报错: Ajax 未设置 contentType 时会报 415 . 后台 RequestBody 承接前台参数,故对参数data的要求为“必传”“JSON”,否则会报40 ...
- Darwin Streaming Server服务器mp4文件点播返回”415 Unsupported Media Type“错误
Darwin Streaming Server中mp4文件点播失败,通过抓包发现服务器返回”415 Unsupported Media Type“错误,如下: RTSP/ Unsupported Me ...
- [.NET Core]ASP.NET Core中如何解决接收表单时的不支持的媒体类型(HTTP 415 Unsupported Media Type)错误呢?
[.NET Core]ASP.NET Core中如何解决接收表单时的不支持的媒体类型(HTTP 415 Unsupported Media Type)错误呢? 在ASP.NET Core应用程序中,接 ...
- angularjs - 415 (Unsupported Media Type)
angularJs+springMVC angular表单提交一个user实体时,报 angularjs - 415 (Unsupported Media Type)错误!! 原因是$http({ u ...
- request 报错The remote server returned an error: (415) Unsupported Media Type.
开发时遇到个问题,程序访问数据库数据,给服务器发送请求时,老是报错,返回的错误页面是: HTTP Status 415 - Unsupported Media Type type Status rep ...
- System.Net.WebException : The remote server returned an error: (415) UNSUPPORTED MEDIA TYPE
I am having problems with a bit of code that accesses a restful web service. Running this code, it e ...
- RestTemplate远程调用POST请求:HTTP 415 Unsupported Media Type
这是本项目的接口 称为client @POST @Path("/{urlcode}") @Consumes(MediaTypes.JSON_UTF_8) @Produces(Med ...
随机推荐
- IO流4
IO流的分类 根据处理数据类型的不同分为:字符流和字节流 根据数据流向不同分为:输入流和输出流 字符流和字节流 字符流的由来: 因为数据编码的不同,而有了对字符进行高效操作的流对象.本质其实就是基于字 ...
- jQuery的核心思想
jQuery?----www.jQuery.com jQuery的理念:write less, do more jQuery的成就:世界排名前100的公司,46%都在使用jQuery,远远超过其他库, ...
- 箭头函数=>
箭头函数特点一:没有自己的this对象,其this对象为所在环境 特点二 :没有arguments参数 可以用...rest代替特点三:不能使用构造函数,不可使用new命令,否则会报错 //函数的扩展 ...
- L4170[CQOI2007]涂色
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i <= b; ...
- JS 中构造函数和普通函数的区别
原来只是随意的了解了下 , 但是最近有点忘了 于是详细了解下 加深下印象. 1.构造函数也是一个普通函数,创建方式和普通函数一样,但构造函数习惯上首字母大写 2.构造函数和普通函数的区别在于:调用方式 ...
- SpringBoot第二天
一,SpringBoot 整合 jsp 技术 1,创建项目 2,修改 pom 文件,添加坐标 <project xmlns="http://maven.apache.org/POM/4 ...
- Go中的结构体
前面我们或多或少的都使用了结构体这种数据结构,本身结构体也有很多特性,我们一一来看. 结构体的作用是将一个或者多个任一类型的变量组合在一起的数据类型,类似于我们在Java中class的作用.在结构体重 ...
- LayDate使用
layDate非常愿意和您成为工作伙伴.她致力于成为全球最用心的web日期支撑,为国内外所有从事web应用开发的同仁提供力所能及的动力.她基于原生JavaScript精心雕琢,兼容了包括IE6在内的所 ...
- PCB学习总结
一.电子设计流程概述:项目立项------元件创库----------原理图设计-----------封装绘制-------pcb设计--------生产文件的输出--------pcb文件加工 二. ...
- ASP.NET CORE 2.* 利用集成测试框架覆盖HttpClient相关代码
ASP.NET CORE 集成测试官方介绍 我的asp.net core 项目里面大部分功能都是去调用别人的API ,大量使用HttpClient,公司单元测试覆盖率要求95%以上,很难做到不mock ...