I am working on web site cleaning apps in Scala. The site I'm scraping is heavily session oriented, so I need to hit the site once to get the session id before I can do anything else.
I get a connection to get the session id, for example:
url.openConnection().asInstanceOf[HttpURLConnection]
It works great. The associated field of the returned HttpURLConnection is false, and it turns to true when I call .connect () on it. No problems.
The first hint of the problem occurs when I end the connection and call .disconnect () on it. The .connected field remains valid. Hm.
So now I have a session id, and I'm going to get a page that has the form I want on it. I'm calling
url.openConnection().asInstanceOf[HttpURLConnection]
again, like last time - the same code, in fact - except that the HttpURLConnection that it gives me has a .connected field set to true! At first I thought that somehow it gives me the same object that it gave me before, but no, the memory identifier is different.
So now, when I call .setRequestProperty () on the connection, it explodes with IllegalStateException: already connected.
I do not understand how to use HttpURLConnection?
Notes: Scala 2.9.2, Java 6.0. Also, the URL objects that I call .openConnection () on are different objects, not the same.
Thanks...