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); String cookiesURL = cookieMgr.getCookie(url);
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?
2 Answers
Answers 1
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.
Answers 2
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.
0 comments:
Post a Comment