0
我试图使用asp.net。当我尝试调用服务,我得到错误发布数据到Java REST服务响应错误:无法加载资源:服务器400(错误请求)的状态
Failed to load resource: the server responded with a status of 400 (Bad Request).
请指导我在这我GOOGLE了一下但没有发现solution.I已经启用了我的服务中加入代码CORS领域工作,因为在服务器应用下面提到
@RequestMapping(value = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Status addEmployee(@RequestBody Employee employee, HttpServletRequest request, HttpServletResponse response) {
try {
response.addHeader("Access-Control-Allow-Origin","*");
dataServices.addEntity(employee);
return new Status(1, "Employee added Successfully !");
} catch (Exception e) {
// e.printStackTrace();
return new Status(0, e.toString());
}
}
在asp.net APPLICAT离子
$.ajax({
crossDomain: true,
type: 'POST',
url: "http://localhost:9091/employeeservice/employee/create",
data: JSON.stringify({
"id": 10,
"first_name": "narayan",
"last_name": "bhat",
"email": "[email protected]",
"phone": "4545454545"
}),
error: OnErrorCall,
success: OnSuccessCall,
dataType: "json",
contentType: "application/json"
});
function OnSuccessCall(response) {
alert(response.d);
}
function OnErrorCall(response) {
alert(response.status + " " + response.statusText);
}
请指导我在这里我是新来的asp.net。
我必须使用JavaScript来调用REST服务。 – allDroid
您是否尝试过使用https://www.getpostman.com测试其他服务?我要求你在Chrome中添加扩展并至少在Postman中测试一次。 – Keval
在邮政人的工作正常,但它不工作在asp.net ajax呼叫 – allDroid