繁体   English   中英

415-不支持的媒体类型错误| angularjs + Spring3.2

[英]415- Unsupported Media Type Error | angularjs + Spring3.2

我在浏览器中收到415错误。 我找不到错误。 能否请你帮忙。

  • loginController.js

$ scope.user = {电子邮件:“ admin”,密码:“ password”};

$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

@Controller

@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");
}

}

网络通话

请求和响应头

杰克逊(Jackson)映射器解决了该问题。

在pom.xml中添加Jackson-mapper的Maven依赖项

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM