setCookie

@Autowired
private RestTtestRestTemplate

@RtopControllerAnnotation
@ResponseBody
@RequestMapping(value = "/test.json", method = RequestMethod.GET)
public RtopHttpResult test(HttpServletRequest request, HttpServletResponse response) {
RestTemplate restTtestRestTemplate= new RestTemplate();
MultiValueMap<String, String> mParams = new LinkedMultiValueMap<String, String>();
mParams.add("loginName", "admin");
mParams.add("pwd", "Abc12345");
mParams.add("remember", "true");
mParams.add("LOGIN_TYPE", "bucSsoLoginHandler");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, String>> httpRequest = new HttpEntity<MultiValueMap<String, String>>(mParams, headers);
ResponseEntity<Object> responseEntity = restTtestRestTemplate.postForEntity( "http://lcoalhost:8080/iam/doLogin.json", httpRequest, Object.class);
Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
List<String> setCookie = responseEntity.getHeaders().get("Set-Cookie");
if (setCookie!= null){
String cookie = setCookie.toString().replace("[", "").replace("]", "");
response.setHeader("Set-Cookie",cookie);
}
return Success(null);
}
posted @ 2019-06-05 18:51  且听风吟soft  阅读(911)  评论(0编辑  收藏  举报