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 I want to know if I can reuse a HttpWebRequest by changing the url and getting the request again. The code in question is below. This code checks if a range of urls exists.
static void storeList(TextWriter sw, string urlTemplate, int start, int end)
{
for (int i = start; i < end; i++)
{
var url = string.Format(urlTemplate, i);
var req = (HttpWebRequest)HttpWebRequest.Create(url);
{
req.Method = "HEAD";
tryHttpWebRequest
{
var resp = req.GetResponse();
sw.WriteLine(i);
}
catch (Exception e)
{
}
}
}
sw.Flush();
}
See Question&Answers more detail:os