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);
}
标签:mParams,headers,add,responseEntity,new,setCookie 来源: https://www.cnblogs.com/wwqwwq/p/10981332.html