当我尝试从angularjs调用java restful服务时出现以下错误:
POST http://localhost:8080/test/info/ 405 (Method Not Allowed)
这是angularjs代码
...
$http.defaults.headers.common['content-type'] = 'application/json';
$http.defaults.headers.common['content-type'] = 'application/json';
$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;
var userdata = { username: 'test', password: '123456' };
$http({ method: 'POST', url: '/test/info', data : userdata })
.success(function (userdataResponse) {
$rootScope.userData = userdataResponse;
});
...
这是java代码
@POST
@Path("/test/info")
@Produces("application/json")
@Consumes("application/json")
public Response getDataUserInformation(Userdata request){
Userdata user = userService.findByUser(request.getUser());
Gson gson = new Gson();
DataUserDTO dataUserDTO = dataUserService.findByID(user.getID());
return Response.ok().entity(gson.toJson(DataUserDTO).toString()).build();
}
有什么问题?我有相同的登录功能,但效果不错,但这不是......
感谢您的帮助
答案 0 :(得分:-1)
是否正在使用以下内容?可能需要.json。
$http({ method: 'POST', url: '/test/info.json', data : userdata })
.success(function (userdataResponse) {
$rootScope.userData = userdataResponse;
});