如何从响应中获取多个set-cookie

时间:2017-04-04 18:46:41

标签: resttemplate

我有一个返回两个Set-Cookie的Web服务调用。从响应中,我只能看到/得到一个(第一个,很奇怪。难道不应该是最后一个吗?)

使用CURL

< Set-Cookie: lat=MTQ5MTMyOTE5MzYyNQ==;domain=my.company.com;path=/
< Set-Cookie: vid=some_random_text;domain=my.company.com;path=/;HttpOnly

我的代码:

RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new FormHttpMessageConverter());

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("Content-Type", "application/x-www-form-urlencoded");
...


MultiValueMap<String, String> payload = new LinkedMultiValueMap<String, String>();
payload.add("_charset_", "UTF-8");
...

HttpEntity<?> request = new HttpEntity<MultiValueMap<String, String>>(payload, headers);


ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);

List<String> cookies = response.getHeaders().get("Set-Cookie");

Cookie只有第一个cookie和长度为1。我正在尝试检索第二个Set-Cookie值。

0 个答案:

没有答案