3
내가 서버에 데이터를 전송하고 있습니다
와 요청 후 HTTP 상태를 받고 난 적절한보기스프링 MVC
@RequestMapping(method = RequestMethod.POST)
public String Login(@ModelAttribute("Attribute") Login login, Model model,HttpServletRequest request) {
// Prepare acceptable media type
ArrayList<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_XML);
// Prepare header
HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);
HttpEntity<Login> entity = new HttpEntity<Login>(login, headers);
// Send the request as POST
try {
ResponseEntity<Login> result = restTemplate.exchange("http://www.../user/login/",
HttpMethod.POST, entity, Login.class);
} catch (Exception e) {
}
//here i want to check the received status
if(status=="OK"){
return "login"
}
else
return "redirect:/home";
}
나는 위의 코드에서 약간의 문제가 있다고 생각한다. 나는 항상 null이되도록 statusCode를 보았다. 나는 서버를보고있어 요청이 완료되었음을 알 수있다. 왜 그런지 알고 있니? –
@AlexDowining Typo (필자는 result.getStatusCode 대신 entity.getStatusCode를 입력했습니다). 편집 된 버전을 사용해보고 더 잘 작동하는지 확인하십시오. – erikxiv
나는 이것을 시도하고 있지만 ResponseEntity에서 예외를 취하고있다 result = restTemplate.exchange ("http : //www.../user/login/", HttpMethod.POST, entity, Login.class) ; 그리고 난 줄을 실행할 수 없습니다 : statusCode = result.getStatusCode(); –