问题.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 ...
随机推荐
- bootstrap datatable editor 扩展
需求: a. 表单样式更改. b. 表单大小更改. 思路: a. 通过设置modal css更改样式和大小.缺点,全局性的更改. b. 更改bootstrap-editor,可以通过某种方式将参数传入 ...
- Oracle 统计信息介绍
统计信息自动执行需要以下条件满足: dba_autotask_task 字段status值ENABLED dba_autotask_client 字段status值ENABLED dba_auto ...
- ubuntu防火墙规则之ufw
前言 因公司项目的需求,需要对客户端机器简便使用防火墙的功能,所以可在页面进行简便设置防护墙规则,当然,这个功能需求放到我手上我才有机会学到.因为客户端机器都是ubuntu的,所以当然用了ubuntu ...
- linuk挂载命令
1 Linuk挂在命令如下(将一个目录下面的东西挂在到另一个目录上面) mount -bind -o rw /data/vsftpd/原目录 /data/vsftpd/目标目录 2 查看所有的挂载 ...
- ruby镜像报错,compass安装报错
在这几天在电脑上安装compass一直报错,很无语.因为安装的ruby和sass都没有问题,虽然是很久之前安装的. sass # 更新sass gem update sass # 检查sass ...
- 史上最强Java开发环境搭建
在项目产品开发中,开发环境搭建是软件开发的首要阶段,也是必须阶段,只有开发环境搭建好了,方可进行开发,良好的开发环境搭建,为后续的开发工作带来极大便利. 对于大公司来说,软件开发环境搭建工作一般是由运 ...
- Core CLR 自定义的Host官方推荐的一种形式(第一种)
.Net Core CLR提供两种Host API访问 托管代码的形式,按照微软官方的说法,一种是通过CoreClr.DLL来直接调用托管生成的DLL程序集,另外一种是通过CoreClr里面的C导出函 ...
- webpack4核心模块tapable源码解析
_ 阅读目录 一:理解Sync类型的钩子 1. SyncHook.js 2. SyncBailHook.js 3. SyncWaterfallHook.js 4. SyncLoopHook.js 二: ...
- Java并发编程实战笔记—— 并发编程2
1.ThreadLocal Java中的ThreadLocal类可以让你创建的变量只被同一个线程进行读和写操作.因此,尽管有两个线程同时执行一段相同的代码,而且这段代码又有一个指向同一个ThreadL ...
- C#将图片转换成字符画
先看一下效果图 在Main方法中调用(首先要添加程序集System.Drawing,然后引入命名空间System.Drawing) ConvertToChar(new Bitmap(@"D: ...