Tag: http status code 415

Http 415 JSON不支持的媒体types错误

我用JSON请求调用REST服务,并给出Http 415“不支持的媒体types”错误。 请求内容types设置为(“Content-Type”,“application / json; charset = utf8”)。 它工作正常,如果我不包括在请求中的Json对象。 我正在使用google-gson-2.2.4库的json。 我尝试使用几个不同的库,但它没有任何区别。 任何人都可以帮我解决这个问题吗? 这是我的代码: public static void main(String[] args) throws Exception { JsonObject requestJson = new JsonObject(); String url = "xxx"; //method call for generating json requestJson = generateJSON(); URL myurl = new URL(url); HttpURLConnection con = (HttpURLConnection)myurl.openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setRequestProperty("Content-Type", "application/json; charset=utf8"); con.setRequestProperty("Accept", "application/json"); con.setRequestProperty("Method", […]

POST JSON失败,415不支持的媒体types,Spring 3 mvc

我想发送一个POST请求到一个servlet。 请求通过jQuery以这种方式发送: var productCategory = new Object(); productCategory.idProductCategory = 1; productCategory.description = "Descrizione2"; newCategory(productCategory); newCategory在哪里 function newCategory(productCategory) { $.postJSON("ajax/newproductcategory", productCategory, function( idProductCategory) { console.debug("Inserted: " + idProductCategory); }); } 和postJSON是 $.postJSON = function(url, data, callback) { return jQuery.ajax({ 'type': 'POST', 'url': url, 'contentType': 'application/json', 'data': JSON.stringify(data), 'dataType': 'json', 'success': callback }); }; 用萤火虫,我看到JSON发送正确: {"idProductCategory":1,"description":"Descrizione2"} 但是我得到415不支持的媒体types。 […]