When you make a call to your login api
, most probably you are getting the cookie in first attempt and in the next ones you can not.
This is because cookie is already there but not on the headers anymore.
You might want to save the cookie in your first call and refresh it after some time according to your lifecycle requirements.
You can try and see this with Postman. It's a great tool for REST. Here is the link.
Another possible reason for that may be:
Cookie returns null or not the expected result when using volley library because when you call this:
response.headers.get("Set-Cookie");
Response headers are not mapped properly. Calling
response.headers
returns a Map
object but it doesn't know the type. That's where it breaks. So a better approach would be to receive the Map
object first properly like this:
Map<String, String> map = response.headers;
then:
String cookie = map.get("Set-Cookie");