JSON 415 Desteklenmeyen medya türü ile başarısız POST, Spring mvc 3
Bir sunucu uygulaması için bir POST isteği göndermek için çalışıyorum. İsteği bu şekilde jQuery ile gönderilir:
var productCategory = new Object();
productCategory.idProductCategory = 1;
productCategory.description = "Descrizione2";
newCategory(productCategory);
nerede newCategory
function newCategory(productCategory)
{
$.postJSON("ajax/newproductcategory", productCategory, function(
idProductCategory)
{
console.debug("Inserted: " idProductCategory);
});
}
ve postJSON
$.postJSON = function(url, data, callback) {
return jQuery.ajax({
'type': 'POST',
'url': url,
'contentType': 'application/json',
'data': JSON.stringify(data),
'dataType': 'json',
'success': callback
});
};
Firebug ile bu JSON doğru gönderilir görüyorum
{"idProductCategory":1,"description":"Descrizione2"}
Ama 415 Desteklenmeyen medya türü. Kontrolör imzası Spring mvc
@RequestMapping(value = "/ajax/newproductcategory", method = RequestMethod.POST)
public @ResponseBody
Integer newProductCategory(HttpServletRequest request,
@RequestBody ProductCategory productCategory)
Birkaç gün önce çalışıyordu, şimdi değil. Daha fazla kod gerekirse göstereceğim. Teşekkürler
CEVAP
Bu daha önce başına gelmiş Bahar @ResponseBody ile geçirdim ve kabul Başlığı isteği ile gönderildi çünkü. Üstbilgi kümesi ile bir WordPress kullanmak için bir ağrı olabilir, ama bu benim için source kabul çalıştı
$.postJSON = function(url, data, callback) {
return jQuery.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
'type': 'POST',
'url': url,
'data': JSON.stringify(data),
'dataType': 'json',
'success': callback
});
};
İçerik Türü Başlığı @veri isteği istemciden gönderilen belirlemek için RequestBody tarafından kullanılır. @İstemciye veri yanıt olarak gönderilen belirlemek için ResponseBody tarafından kullanılan başlık kabul. Hem başlıkları ihtiyacımız var.
Nasıl bir WordPress kullanmak -$.() po...
Uygun MIME türü için PDF medya dosyala...
Yöntemle girişimi 'Sistemi.Web.Ya...
Spring MVC (@ResponseBody)yanıt içerik...
Post Python İstekleri kullanarak JSON...