1

I am working on a project where I want to send a POST REST call and get the response and in the response, there are few cookies. among those, I want to get X-Bonita-API-Token and pass it to the frontend.

I used String set_cookie = httpHeaders.getFirst(HttpHeaders.SET_COOKIE); this return only the first cookie but i need the second.

my code

final String uri = "http://localhost:8080/bonita/loginservice";
    RestTemplate template = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<ApiRequest> entity = new HttpEntity<>(apiRequest, headers);
    template.getMessageConverters().add(getMappingJackson2HttpMessageConverter());
    HttpEntity<String> response = template.exchange(uri, HttpMethod.POST, entity,String.class);
    HttpHeaders httpHeaders = response.getHeaders();
    String set_cookie = httpHeaders.getFirst(HttpHeaders.SET_COOKIE);

Here are the returned cookies.

enter image description here

can anyone help me to retrieve X-Bonita-API-Token?

Thanks.

D.Anush
  • 147
  • 6
  • 15
  • Have you tried this solution? https://stackoverflow.com/a/22853923/3713193 o you could try creating an interceptor. – Antonio Vida Oct 06 '20 at 07:21
  • this one might help https://stackoverflow.com/questions/34181175/how-to-get-more-than-one-set-cookie-header-from-response-using-retrofit-okhttpcl – Sanjay Jain Oct 06 '20 at 08:01

0 Answers0