setCookie

Posted wwqwwq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);

以上是关于setCookie的主要内容,如果未能解决你的问题,请参考以下文章