3

I'm using HttpUrlConnection to perform some http request and I need to keep a session alive.

I read the doc which just say to add

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

but it does not say where.

Should I add this every time I create a HttpUrlConnection and do a request? I can't find any example...

jul
  • 33,288
  • 64
  • 178
  • 299

1 Answers1

4

CookieHandler.setDefault() sets the system-wide cookie handler. You should call it once.

Sokolov
  • 2,159
  • 2
  • 17
  • 28