Spring MVC 415 Nicht unterstützter Medientyp
Ich verwende Spring 3.2 und versuche, eine Ajax-Post-Anfrage zu verwenden, um ein Array von JSON-Objekten zu senden. Wenn dies relevant ist, habe ich alle Sonderzeichen ausgeblendet.
Ich erhalte den HTTP-Status 415.
Mein Controller ist:
@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 ist:
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");
}
});
}
});
und ein Beispiel für eines der Objekte aus dem Array, das ich veröffentliche, ist das folgende 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"
}
Der Fehler ist:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method
Warum tritt dieser Fehler auf - weiß jemand Bescheid?