Retrieve the contents of cookies using Java
I need to retrieve the properties of the cookies stored upon visiting a web page. Specifically,
- Name
- Host
- Expiration Date
Is t开发者_如何学Gohere a library that I can use?
EDIT: I apologize for the lack of detail.. I am employing Selenium to retrieve the WEB page. Asserting the presence of the cookie (and ultimately deleting it) is present in Selenium's native functionality. Reading the contents, however, is something I was hoping to do...
You can use
selenium.getCookieByName("CookieName")
to read the cookie by its name. This returns the cookie value as String
selenium.getCookie()
to get all the cookies in the page. You can assign this to a string and read it.
Finally to delete it you can use :
selenium.deleteCookie("CookieName")
Here is an excellent resource I stumbled upon, using the java.net API - http://www.hccp.org/java-net-cookie-how-to.html
For cookie handling use WebDrive manage() e.g. get cookie's value as string
driver.manage().getCookieNamed(cookieName).getValue();
精彩评论