我正在尝试开发Spring MVC应用程序。并在客户端使用JQuery将Json发布到webservice 但我有这个错误:代码415 |不支持的媒体类型
Jquery Part:
jQuery.post(rootURL + "/json/deployWorkflow",JSON.stringify({ "command": "on" }), function(response) {
console.log("ok........");
})
java部分:
@RequestMapping(value = "/deployWorkflow" , method = RequestMethod.POST)
@ResponseBody
public void deployWorkflow(@RequestBody ObjectNode jsonData){
System.out.println(jsonData.toString());
}
答案 0 :(得分:0)
我找到了一个解决方案:
JQuery部分:
jQuery.ajax({
type: 'POST',
contentType : 'application/json; charset=utf-8',
url: rootURL + "/json/deployWorkflow",
dataType: "json",
data:x,
async: false,
success: function(data, textStatus, jqXHR){
alert('ok........data' + data );
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error: status: "+textStatus+" er:"+ errorThrown);
}
});
java部分:
@RequestMapping(value = "/deployWorkflow" , method = RequestMethod.POST, headers="Accept=application/json")
@ResponseBody
public void deployWorkflow(@RequestBody ObjectNode jsonData){
System.out.println(jsonData.toString());
}