即使知道这个错误,我也无法解决我的问题!
重置服务在此代码中声明:
@POST
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Path("/addProduct")
public void addProductToShoppingBag(JSONObject object) throws JSONException
我正在使用此javascript发送POST请求:
$.ajax({
header: 'application/json',
type: 'POST',
data: $.toJSON({
member_id: "1",
products_id: ["0","1"]
}),
url: url
}).done(success).error(failure);
我得到了415 - 不支持的媒体类型错误!任何想法?
答案 0 :(得分:6)
您想要设置 **1 JsonSchema schema = new JsonSchema();
2 schema.Type = JsonSchemaType.Object;
3 schema.Properties = new Dictionary<string, JsonSchema>
4{
5 { "name", new JsonSchema { Type = JsonSchemaType.String } },
6 {
7 "hobbies", new JsonSchema
8 {
9 Type = JsonSchemaType.Array,
10 Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } }
11 }
12 },
13};**
。您的标题格式不正确
开关:
contentType
要
header: 'application/json',
正确的标头需要包含contentType: "application/json;charset=utf-8",
,jQuery会为你处理