나머지 서비스를 치는 것이 아니라, 여전히 작동하지 않는 것 같습니다 그리고 내가이 jQuery를 보내고 Status Code: HTTP/1.1 415 Unsupported Media Type
내가 포럼에 비슷한 오류를 보았다
무엇입니까 :
$("#btnInsertCustomer").click(function(){
var myObj = {name: "Bill Adama", address:"Vancouver Canada"};
var jsondata = JSON.stringify(myObj);
$.ajax({
type: "POST",
url: "http://localhost:8081/RestDemo/services/customers/add",
contentType: "application/json",
dataType: "json",
data: jsondata,
success: function (resp, status, xhr) {
var msg = "Name: " + resp.name + ", Address: " + resp.address;
alert(msg);
$("#successPost").html(msg + " - STATUS: " + xhr.status + " " + xhr.statusText);
},
error: function(resp, status, xhr){
alert("Error: " + resp.e);
$("#errorPost").html("Error: " + resp.e + " - STATUS: " + xhr.status + " " + xhr.statusText);
}
});
});
이 다음 자원에
:
@POST
@Path("/add")
@Produces("application/json")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public String addCustomer(Customer customer) {
//insert
int id = customerMap.size();
customer.setId(id);
customerMap.put(id, customer);
//get inserted
Customer result = customerMap.get(id);
return "{\"name\": \" " + result.getName() + " \", \"address\": \"" + result.getAddress() + "\"}";
}
이는 serivce를 치는 나에게 오류를주는되지 않습니다. jQuery 쪽 (확인 된 것 같습니다) 또는 서비스받는 사람이 보낸 데이터 서식을 오류가 있는지 이해할 수 없습니다.
감사합니다. 감사합니다.
UPDATE 1 : DTO를 창조는
$("#btnInsertCustomer").click(function(){
//var myObj = '{"name": "Bill Adama", "address":"Vancouver Canada"}';
//var jsondata = JSON.stringify(myObj);
var NewCustomer = { };
NewCustomer.name = "Bill Adama";
NewCustomer.address = "Vancouver Canada";
var DTO = { 'NewCustomer' : NewCustomer };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:8081/RestDemo/services/customers/add",
data: JSON.stringify(DTO),
dataType: "json",
success: function (resp, status, xhr) {
var msg = "Name: " + resp.name + ", Address: " + resp.address;
alert(msg);
$("#successPost").html(msg + " - STATUS: " + xhr.status + " " + xhr.statusText);
},
error: function(resp, status, xhr){
alert("Error: " + resp.e);
$("#errorPost").html(resp.e + " - STATUS: " + xhr.status + " " + xhr.statusText);
}
});
});
을 전송하려면하지만 난 여전히 같은 오류를 얻을!
도이 방법은 NT 실제로 웹 서비스의 brakpoint을 타격 ...는 GET가 잘 작동을 수행하는 동안. – mzereba
포스터 (파이어 폭스)로 테스트하면 같은 오류가 발생합니다 ... 그래서 분명히 문제는 json을 수락 할 때 Resource 클래스에 있습니다. 어느 누구도이 일을 도울 수 있습니까? – mzereba