如何使用Java在请求中添加cookie

时间:2018-06-06 04:31:38

标签: cookies

我想通过localhost通过基于某些cookie的其他域发送Http请求。我尝试了以下代码,但它没有奏效。有人可以帮忙吗?

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("Set-Cookie", "key=value");
MultiValueMap<String, String> requestData = 
DataTransformation.transformSendVerificationRequest(sendVerificationCodeDTO);
HttpEntity<MultiValueMap<String, String>> httpEntity = new 
HttpEntity(requestData, headers);
String url = this.serviceUrl;

ResponseEntity<SendVerificationCodeResponse> response = 
     this.restTemplate.exchange(url, HttpMethod.POST, httpEntity, 
             SendVerificationCodeResponse.class, new Object[0]);

0 个答案:

没有答案