Android CookieManager getCookie issue

你说的曾经没有我的故事 提交于 2021-02-08 08:20:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!