简体   繁体   English

Android CookieManager

[英]Android CookieManager

I have an application that makes several web calls in order to get authenticated after which a JSON is returned. 我有一个应用程序,它进行了几次Web调用,以便进行身份验证,然后返回JSON。 My web calls are to an https server and I am using HTTPURlConnection. 我的网络呼叫是https服务器,我正在使用HTTPURlConnection。

I need to store the session in a cookie, after researching around, I found this 我需要将会话存储在cookie中,经过研究后,我发现了这一点

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

Under the sessions with cookies header, it tells you to use this code here 在带有cookies标头的会话下,它会告诉您在此处使用此代码

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

However when I try using this code, the new CookieManager(); 但是当我尝试使用这段代码时,新的CookieManager(); part highlights in red and says 部分亮点红色并说

The constructor CookieManager is not visible 构造函数CookieManager不可见

and the Cookiehandler.setDefault also highlights in red and says 并且Cookiehandler.setDefault也以红色突出显示

The method setDefault(CookieHandler) in the type CookieHandler is not applicable for the arguments (CookieManager) CookieHandler类型中的方法setDefault(CookieHandler)不适用于参数(CookieManager)

Does anyone know why this is? 有人知道为什么吗?

Thanks in advance! 提前致谢!

You're probably trying to use the wrong CookieManager class. 您可能正在尝试使用错误的CookieManager类。 In Android there are 2 classes... 在Android中有2个类......

android.webkit.CookieManager
java.net.CookieManager

For this context, you need to use the java.net.CookieManager class. 对于此上下文,您需要使用java.net.CookieManager类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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