Reputation: 10584
Below is my code to get some cookies post authentication in an android application.
String url = "https://host:port/sso/SSOServlet";
BasicCookieStore cookieJar = new BasicCookieStore();
CookieManager cookieMgr = CookieManager.getInstance();
String host = null;
URL urlObj = Util.getUrl(url);
host = urlObj.getHost();
String cookiesHost = cookieMgr.getCookie(host); // value for cookiesHost is JSESSIONID
String cookiesURL = cookieMgr.getCookie(url); // value for cookiesURL is JSESSIONID and a custom Session id for application.
So cookieMgr.getCookie()
returns different value for certain server if I use host
instead of url
. Why is that? For some servers, it returns the same values if I use either host
or url
. Why this might be happening?
This was returning same values for host OR url previously, but this one server I am working with, is returning the values I mentioned in the comments of code.
Upvotes: 2
Views: 1159
Reputation: 91
It is difficult to determine the exact issue causing the varied results without knowing what is being returned for each variable.
Please provide the values of cookiesHost
and cookiesURL
when you are seeing the difference in the cookies.
As mentioned in the first response to your issue if you use example.com
(HOST), a session and a cookie is created for example.com
, then most likely a redirect to the BaseURL www.example.com
creates a new session.
Upvotes: 1
Reputation: 82563
getHost()
returns just the domain name. For instance, google.com
out of http://google.com/search
. I'm guessing your getUrl()
method returns the entire URL.
This gives the CookieManager
instance different inputs, resulting in different outputs.
Upvotes: 1