简体   繁体   中英

Android CookieManager

I have an application that makes several web calls in order to get authenticated after which a JSON is returned. My web calls are to an https server and I am using HTTPURlConnection.

I need to store the session in a cookie, after researching around, I found this

http://developer.android.com/reference/java/net/HttpURLConnection.html

Under the sessions with cookies header, it tells you to use this code here

   CookieManager cookieManager = new CookieManager();
   CookieHandler.setDefault(cookieManager);

However when I try using this code, the new CookieManager(); part highlights in red and says

The constructor CookieManager is not visible

and the Cookiehandler.setDefault also highlights in red and says

The method setDefault(CookieHandler) in the type CookieHandler is not applicable for the arguments (CookieManager)

Does anyone know why this is?

Thanks in advance!

You're probably trying to use the wrong CookieManager class. In Android there are 2 classes...

android.webkit.CookieManager
java.net.CookieManager

For this context, you need to use the java.net.CookieManager class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM