4

I am receiving the exception with this stack trace

Exception in thread "main" java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:2410)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:296)
at com.hello.world.CookieManager.setCookies(CookieManager.java:124)
at com.hello.world.HttpHandler.PostHttps(HttpHandler.java:101)

These are the lines in HttpHandler.PostHttps

URL url = new URL("https://www.example.com/");
HttpsURLConnection httpsConn = (HttpsURLConnection)url.openConnection();
cm.setCookies(httpsConn);

And these are the ones in CookieManager.setCookies

String cookieStr = "name=value";
httpsConn.setRequestProperty("Cookie", cookieStr);

I know that I can't set the cookies header while the connection is open. But I don't call anything on the connection's object except initializing the object using openConnection() then adding cookies.

I also know that calling some other methods such as getHeaderFiles or running a stream will open the connection and no such method is called.

Edit:

I was using JDK 1.6.0.39 I downloaded the latest version 1.7.0.51 and it was fixed. Turns out it was a version problem after all.

Edit 2:

It appeared again, weirdly I gotta add.

0 Answers0