【发布时间】:2014-10-02 06:25:03
【问题描述】:
我在浏览器中收到 415 错误。我无法找到错误。你能帮忙吗?
- loginController.js
$scope.user = {电子邮件:“管理员”,密码:“密码”};
$http.post('/expense-manager-api/login/authenticate', $scope.user, {
headers: {"Content-Type": "application/json"}
}).success(function(login) {
$scope.setError(login.status);
$location.path("main");
}).error(function() {
$scope.setError('Invalid user/password combination');
});
- LoginController.java
@控制器
@RequestMapping("/login")
public class LoginController {
@RequestMapping(value = "/authenticate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public
@ResponseBody
LoginResponse login(@RequestBody LoginRequest loginRequest) {
if (loginRequest.getEmail().equals("admin") && loginRequest.getPassword().equals("password")) {
UUID uuid = UUID.randomUUID();
return new LoginResponse(uuid.toString(), "OK");
}
return new LoginResponse(null, "Invalid user/password combination");
}
}
【问题讨论】:
-
你能在 Firebug 或 Chrome 开发控制台上发布 HTTP 请求的样子吗?
-
@geo 我添加了照片。
-
Spring 似乎正在回归
text/html。您确定日志中没有任何错误吗? -
是的。日志中没有错误。
-
如果我调试服务器端代码。它甚至没有进入该方法的第一行。我的响应主体是“LoginRespone”,它是对象。怎么可能是text/html?
标签: angularjs web-services spring-mvc http-post http-status-code-415