Timeout in HttpWebRequest.GetResponse() for large uploads

R

Ravi

I'm using HttpWebRequest in .NET 1.1 to post data files to a web
server. The data files can potentially be 20mb or more. The relevant
code for this looks essentially like:

Stream reqStream = request.GetRequestStream();
reqStream.Write(data, 0, data.Length);
reqStream.Close();
WebResponse response = request.GetResponse();

My problem is that GetResponse() times out while the file is being
uploaded. My call to Write() is returning immediately rather than
blocking until the data gets sent to the remote server. I know I can
increase the timeout interval but that just pushes out the upper size
limit for data without fixing the real issue.

I've found that if I upload in pieces instead of writing the data all
at once then every call to Write after the first one seems to block
while data from the previous write gets uploaded. That potentially
solves my problem since only the last, small piece will be left when I
call GetResponse.

I can't find any documentation confirming this behavior, though. Is
there any guarantee that if I upload in pieces then my program can
more or less monitor the actual transfer progress. If not, does anyone
have other ideas how I can avoid calling GetResponse() until the
upload is finished?

Thanks,
Ravi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top