Forums Register Login

HttpURLConnection - Stream closed

+Pie Number of slices to send: Send
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());
}
}
+Pie Number of slices to send: Send
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.

 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3758 times.
Similar Threads
Issue with sending xml jaxb object to servlet body
HttpURLConnection got stack when trying to invoke
GET via URLConnection?
How to capture a response from a Server?
Performance Issue: HttpURLConnection
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:39:18.