HttpWebResponse: stream closing

I get a response from HttpWebRequest (using a modified CCR wrapper version of Jeff Richter ), then checking a few headers to decide whether to continue downloading. Sometimes I may not want to continue, so I issue response.Close and request.Abort . Does GetResponseStream need to be released to close the stream, or is it implicit when you call response.Close ?

After issuing GetResponse docs state :

You must call the Close method to close the stream and release the connection. Otherwise, your application may not work.

Does this mean that as soon as we have an answer, then it is imperative to get the stream and close it?

We see some rather strange problems in which downloaded downloads ultimately hush up the system. This seems like the strongest candidate for a resource leak, but ask yourself if anyone else has experience with this problem.

Aside: is GetResponseStream twice safe under the assumption that this is the same stream?

+2
source share
3 answers

Actually calling webResponse.Close () will close the response stream.

The answer is IDisposable, I advise you to use the instruction.

+2
source

HttpWebResponse.Close implicity .

:

Close .

Stream.Close HttpWebResponse.Close, . Stream.Close, HttpWebResponse.Close, . , .

double-GetResponseStream, , , .

+6

- WCF Connections

//Done with the service, let close it.
try
{
   if (client.State != System.ServiceModel.CommunicationState.Faulted)
   {
      client.Close();
   }
}
catch (Exception ex)
{
   client.Abort();
}
0

Source: https://habr.com/ru/post/1772319/


All Articles