1

I was just wondering if it is possible to use multiple java.net.CookieHandler in one application. The only way to use a CookieHandler, I found, is by using the following:

public static void setDefault(CookieHandler cHandler)

I my case, I want to login multiple times into the same site and so I need more then one CookieHandler.

  1. Do I understand this right?
  2. Is there a way to use a CookieHandler not on a global level?

Unfortunately HttpURLConnection doesn't provide such a function like .useCookieHandler(cHandler).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jens Metzner
  • 109
  • 1
  • 13

1 Answers1

1

Instead of setting up a default CookieHandler, just forward the cookies of the given CookieHandler by the following:

HttpURLConnection.setRequestProperty('Cookie', MyCookieHandler.getCookiesOfHost(hostname));

It is also necessary to add the cookies from a HttpUrlConnection to MyCookieHandler. Here is a useful link for doing it.

Jens Metzner
  • 109
  • 1
  • 13