提问RestTemplate如何移除cookie

我需要从CloseableHttpClient迁移到RestTemplate,原来是这样的:

List<BasicNameValuePair> parameters = asList(
new BasicNameValuePair("username", username),
new BasicNameValuePair("password", password));

HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(parameters));

CloseableHttpClient client = createDefault()


CloseableHttpResponse response = client.execute(httpPost);

用RestTemplate改造:

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

MultiValueMap<String, String> map= new LinkedMultiValueMap<>();
map.add("username", username);
map.add("password", password);

ParameterizedTypeReference<Map<String, String>> responseType = new ParameterizedTypeReference<>() {};

HttpEntity<Object> request = new HttpEntity<>(map, headers);

ResponseEntity<Map<String, String>> tokensInfo = restTemplate.exchange(
    url, HttpMethod.POST, request, responseType
);

要如何设置Cookie?

请登录后发表评论

    没有回复内容