HttpWebRequest.GetResponse() buffered read - possible ?

  • Thread starter Thread starter microdevsolutions
  • Start date Start date
M

microdevsolutions

Hello

I've seen examples to read a file from somewhere into a HttpWebRequest
object then write it to a HttpWebResponse object then stream it into a
Stream object, very similar to the following code snipet :-

==============================================
Uri uri = new Uri("http://www.somewhere/pdf/image1.pdf");

HttpWebRequest httpRequest = null;
httpRequest = (HttpWebRequest)WebRequest.Create(uri);

HttpWebResponse httpResponse = null;
Stream responseStream = null;

try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
responseStream = httpResponse.GetResponseStream();
...
==============================================

However if the original file is big (i.e. say 200MB) the first read
(i.e. httpRequest.GetResponse) causes the browser times out (even if
the timeout property is set to something big enough) because the entire
200MB is being read into the HttpWebRequest object. Is there any way
to control how much is read in via the httpRequest.GetResponse(), so
that I can read around 4MB chunks, send this (flush) to the browser,
read another 4MB, send this to the browser, etc.

Other options include asynchronous reads and perhaps an ftp object, but
is it necessary ?

Many thanks
Travis
 
you would have to write an isapi filter, as asp.net buffers the request
before starting the page processing. otherwise the parsing of the form
variables woudln't be available. in iis 7.0 you could do this with asp.net

typically the browser will not read the response until its finished posting
the file anyway. the browser should only timeout if the server is not
responding to its posts (though IE can be flaky on large uploads - remember
there is no recovery to any connection problems).


-- bruce (sqlwork.com)
 
Does anyone know, or have examples of, an alternative that will be able
to read 4MB of the file into a buffer, send/flush, read another 4MB,
send/flush, ... - eg. using an asynchronized read
Thanks
Travis
 
Back
Top