fetching headers | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by manjunathdj

@sriram_1  - Check this for reference - 

https://gist.github.com/justinedelson/10878245

 

Thanks

3 replies

arunpatidar
Community Advisor
Community Advisor
October 11, 2022
Cookie[] cookies = request.getCookies();

if (cookies != null) {
 for (Cookie cookie : cookies) {
   if (cookie.getName().equals("login-token")) {
     //do something
     //value can be retrieved using #cookie.getValue()
    }
  }
}

 

 

request.getHeader("login-token");
Arun Patidar
sriram_1Author
Level 3
October 11, 2022

Thanks for the prompt reply Arun,

I have done that but not able to find the cookie "login-token" from response.

 

I am trying to hit Assets api using java code with access token .. getting 401 unauthorised, But in postman I am able to fetch api because In the header field login-token cookie is there in postman.

 

even when hitting assets api with basic auth also getting 401 unauthorised.

milind_bachani
Adobe Employee
Adobe Employee
October 11, 2022

@sriram_1 hi,

 

If you are using java.net.URLConnection, you can use :

conn.getHeaderField("login-token");


If you are using Apache HTTPClient , you can use :

response.getFirstHeader("login-token").getValue();


Thanks,

Milind

sriram_1Author
Level 3
October 11, 2022

Hi miland,

I have used the same but there is no header field named "login-token" in response.

 

 

manjunathdj
manjunathdjAccepted solution
New Member
October 11, 2022

@sriram_1  - Check this for reference - 

https://gist.github.com/justinedelson/10878245

 

Thanks