Am I able to reuse a HttpWebRequest?

前端 未结 3 542
南笙
南笙 2020-11-30 10:47

Am I able to reuse a HttpWebRequest?

It seems like the 3rd request to a site causes a operation to time out. It seems like each request creates a new connection, so

3条回答
  •  醉梦人生
    2020-11-30 11:41

    You should be ok if you just call Close on your response. You are only allowed so many "open" connections, so the reason it is failing is because it can't open a new connection.

    Once you are done with the response, you need to close it... no need to reuse anything.

    From the MSDN article:

    You must call either the Stream.Close or the HttpWebResponse.Close method to close the response and release the connection for reuse. It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error.

提交回复
热议问题