I am using Spring 3.2 and try to use an ajax post request to submit an array of json objects. If this is relevant, I escaped all special characters.
I am getting an HTTP Status of 415.
My controller is:
@RequestMapping(value = "/save-profile", method = RequestMethod.POST,consumes="application/json")
public @ResponseBody String saveProfileJson(@RequestBody String[] profileCheckedValues){
System.out.println(profileCheckedValues.length);
return "success";
}
jquery is:
jQuery("#save").click(function () {
var profileCheckedValues = [];
jQuery.each(jQuery(".jsonCheck:checked"), function () {
profileCheckedValues.push($(this).val());
});
if (profileCheckedValues.length != 0) {
jQuery("body").addClass("loading");
jQuery.ajax({
type: "POST",
contentType: "application/json",
url: contextPath + "/sample/save-profile",
data: "profileCheckedValues="+escape(profileCheckedValues),
dataType: 'json',
timeout: 600000,
success: function (data) {
jQuery('body').removeClass("loading");
},
error: function (e) {
console.log("ERROR: ", e);
jQuery('body').removeClass("loading");
}
});
}
});
and an example of one of the objects from the array I am posting is the following json:
{
"id": "534213341",
"name": "Jack Lindamood",
"first_name": "Jack",
"last_name": "Lindamood",
"link": "https://www.facebook.com/jack",
"username": "jack",
"gender": "male",
"locale": "en_US",
"updated_time": "2013-07-23T21:13:23+0000"
}
The error is:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method
Why is this error happening - does anyone know?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…