我正在使用Spring Boot 1.2有FrontEnd Web应用程序和Backend Web应用程序 . FrontEnd Web应用程序使用Angular和Spring Boot 1.2构建 . FrontEnd Web应用程序使用Spring Boot 1.2构建 .
FrontEnd Web应用程序使用RestTemplate调用BackEnd Web应用程序 . 从FrontEnd Web应用程序到BackEnd Web应用程序使用RestTemplate的所有GET请求始终正常 .
POST请求一直使用RestTemplate are not . 在10个POST请求中,1个POST请求导致 400 BAD REQUEST .
POST请求始终发布JSON . RestTemplate已配置为设置“Accept”(“application / json”)和“Content-Type”(“application / json”)标头 .
RestTemplate抛出的错误是
{
"timestamp": "2015-04-04 18:35:50",
"errorCode": "BAD_REQUEST",
"message": "400 Bad Request",
"data": "<html><body><h1>400 Bad request</h1> Your browser sent an invalid request. </body></html>"
}
任何见解将不胜感激 . 是Spring抛出此异常还是Tomcat抛出此异常?
FrontEnd应用程序有以下终点:
@RequestMapping(value = "/manage/user", method =RequestMethod.POST,
consumes = { "application/json" }, produces = { "application/json" })
@ResponseBody public UserResponse manageUser(@RequestBody User user) {
...
RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_XML,
MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<User> entity = new HttpEntity<>(user, httpHeaders);
// Call back-end application
UserResponse userResponse =
restTemplate.postForObject(userServiceURL, user, UserResponse.class);
// Random 400 occurs here, thrown by RestTemplate.postForObject()
...
return userResponse;
}
BackEnd应用程序有以下终点:
@RequestMapping(value = "/user", method =RequestMethod.POST,
consumes = { "application/json" }, produces = { "application/json" })
@ResponseBody public UserResponse create(@RequestBody User user) {
...
// save update user
...
}