HttpWebRequest timeouts?

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I create a HttpWebRequest as follows:

m_req = (HttpWebRequest) WebRequest.Create(url);
m_req.Timeout = 1000*1000;
m_req.Method = "POST";
// issue request

I issue my request and receive the HTTP headers. However as the
request is a long running dynamic request for computed data the body
will not be sent for some time. What happens to me is that the request
times out on the Read way before my 1000secs is up! I can see no other
timeout to set to prevent this happening - is there any other
workaround?

HttpWebResponse res = (HttpWebResponse) m_req.GetResponse();
// I can see res.Headers
// Read on res.GetResponseStream() times out

The reason that the server sends the HTTP headers before the body is
because the requests are dynamic it can NOT predict the size of the
response document and therefore just produces it as it process the
request (e.g. a large database query of indeterminate response size).

Many thanks in advance for any useful answers!
 
Have you tried setting the timeout to System.Threading.Infinite?

-mike
MVP
 
The default behavior for ASP.NET is to buffer output.
Set the BufferOutput property to false, e.g.
System.Web.HttpResponse.BufferOutput = false;
This may solve your problem.
HTH.
 
Unfortunately setting the timeout to infinite makes no difference. I
suspect that the timeout is cancelled by the arrival of the HTTP
headers. I suspect that the problem is that the delayed arrival of the
HTTP body is what causes the timeout.

I'm not using ASP.NET and therefore a suggestion to set
HttpResponse.BufferOutput to false does not help either.

Many thanks for the answers.
 
Another possibility is to edit the machine.config file and change the
httpRuntime's executionTimeout attribute (and if need be the
maxRequestedLength while you are at it). If that does not pan out, I'm
afraid you've run into a brick wall using System.Net.HttpWebResponse.

I realized that you are not using ASP.NET, but I'm afraid that is the (most
likely) way to make it work if it's using the.Net framework. Web
services/ASP.NET offers a richer .NET framework API for making HTTP
Requests/Responses.

Last possibility is to use unmanaged C++ with Internet Server API (ISAPI)
Extensions.

I'm all tapped out of ideas.

Good luck.
 
Is the URL you're posting to available externally? I'd like to try it. Can
you post your URL and possibly your client code?

Thanks,

Ron
 
Back
Top