问题
I am setting a cookie using cookiemanager setcookie API, when I do cookiemanager getcookie I am not getting the domain & expiry date below is my code.
String cookieString = cookie.getName() + "=" + cookie.getValue() + "; Domain=" + cookie.getDomain()+"; expires=" + cookie.getExpiryDate();
CookieManager.getInstance().setCookie("http://mydomainname.com", cookieString);
String cookie = CookieManager.getInstance().getCookie("http://mydomainname.com");
Any idea why cookiemanager getcookie doesn't return domain & expiry date. Is it a bug ?
Thanks, Kumar.
回答1:
Not a bug - just read the documentation. The Android API docs say that getCookie() returns a string "using the format of the 'Cookie' HTTP request header"
The format of the Cookie: request header is a list of cookie name/value pairs separated by semicolons - it does NOT contain domain or expiry information, since a cookie is sent only if the URL matches and it has not expired. The CookieManager.getCookie() method does the same - it returns all the cookies that match the URL supplied and which have not expired.
来源:https://stackoverflow.com/questions/15122674/android-cookiemanager-getcookie-issue