我正在使用 JAX-RS 构建 Restufl Web 应用程序,我在使用使用 json 对象的 post 方法调用 Web 服务时遇到问题。我必须使用 jquery 调用 web 服务,
这是方法
@POST
@Path("/client")
@Consumes(MediaType.APPLICATION_JSON)
public Response showClient(Client c){
String name = c.getAdresseCl() + ""+ c.getEmailCl();
ResponseBuilder builder = Response.ok(name);
builder.header("Access-Control-Allow-Origin", "*");
builder.header("Access-Control-Max-Age", "3600");
builder.header("Access-Control-Allow-Methods", "GET");
builder.header(
"Access-Control-Allow-Headers",
"X-Requested-With,Host,User-Agent,Accept,Accept-Language,Accept-Encoding,Accept-Charset,Keep-Alive,Connection,Referer,Origin");
return builder.build();
}
使用 jquery 进行客户端调用:
var data={'adressCl':'myAdress','emailCl':'example@domain.com'};
$.ajax({
"type":"post",
"dataType":"json",
"data":data,
"url":"http://localhost:9080/FournisseurWeb/jaxrs/clients/client",
"success":function(res){
console.log(res);
}
});/*
$.post("http://localhost:9080/FournisseurWeb/jaxrs/clients/client",data,function(res){
console.log(res);
});*/
我收到此错误:“NetworkError: 415 Unsupported Media Type please help! and thx提前