This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection - Stream closed

 
marc spoon
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
i change the Request Method to "HEAD" and try to write the Header to stdout, but i get an IOException "Stream closed".
Anyone knows why?
URL url = new URL("http://blabla.com");
HttpURLConnection conn;
try
{
conn = (HttpURLConnection) url.openConnection();
//disconnect to change Request Method
conn.disconnect();
conn.setRequestMethod("HEAD");
//and connect again
conn.connect();
BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while((line = input.readLine()) != null)
{
System.out.println(line);
}
input.close();
} catch (IOException ioe) {
System.out.println("IOException " + ioe.getMessage());
}
}
 
Bill Siggelkow
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess the problem is that you have disconnected ... You may not be allowed to reconnect after a disconnect ... the following quote is from the HttpUrlConnection javadoc for the disconnect method ...

Indicates that other requests to the server are unlikely in the near future. Calling disconnect() should not imply that this HttpURLConnection instance can be reused for other requests.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic