标签:
现在做的一个项目是做app服务端的,需要从app接收json的请求数据,服务端框架用的是SpringMVC,所以自然而然的想到直接用@RequestBody来接收json数据,
格式如下:
public ResponseProtocolMap login(@RequestBody JSONObject requestJson,HttpServletRequest request) { ResponseProtocolMap responseProtocolMap = null; //中间内容省略。。。 return responseProtocolMap; }
刚开始导入的是org.json.jar的org.json.JSONObject的包,请求的时候,出现了415错误:
HTTP Status 415 - type Status report message description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method. Apache Tomcat/7.0.64
在这个问题上找了很久解决方法,都没有找到,本来还以为SpringMVC不支持直接接收json呢,后来将json包换成了net.sf.json-lib.jar的net.sf.json.JSONObject就解决问题了
注:测试了用ajax直接传json数据还是会出现415错误,如果直接用http请求post提交json的数据流,测试是正常的,不懂如果是用ajax请求要怎么接收,知道的朋友麻烦帮忙说下,谢谢。
SpringMVC @RequestBody接收JSON报HTTP 415问题的解决方法
标签:
原文地址:http://my.oschina.net/zchuanzhao/blog/514731