title: WebRequest - .timeout question
body: <p>For a little more background, please see:  <a href="https://stackoverflow.com/questions/7166237/problem-with-c-http-put-request-code">Problem with C# HTTP PUT request code</a></p>
  
  <p>I am using the C# WebRequest method to upload a file to S3.  I already have a pre-signed URL that S3 is giving me for the upload.  I originally had a problem where if I was uploading a large file, the transfer would stop a few minutes after starting.  A comment on my other post said it was the .timeout that was causing it.  Sure enough it was.</p>
  
  <p>My question is this:  What should I set the .timeout to or how can I calculate what to set it do based on the size of the file that I am going to transfer?  <br><br>I don't want to start a WebRequest with a 60 minute timeout when I am only going to be sending a small file to S3, but then again I could also be uploading a gigabyte file to S3 also and if the timeout goes off before the file is done, the transfer will be interrupted.</p>
  
  <p>Also how would I trap for a connection timeout?  Would the .timeout be used for that also?  What if I only want to try a connection for 30 seconds to see if S3 responds to my web PUT request and if doesn't then have it timeout.</p>
  
  <p>My code is:</p>
  
  <pre><code>WebRequest request = WebRequest.Create(PUT_URL_FINAL[0]);
  //PUT_URL_FINAL IS THE PRE-SIGNED AMAZON S3 URL THAT I AM SENDING THE FILE TO
  
  request.Timeout = 360000; //6 minutes -- If the transfer is over 6 minutes, it stops.
  
  request.Method = "PUT";
  
  //result3 is the filename that I am sending                                     
  request.ContentType =
      MimeType(GlobalClass.AppDir + Path.DirectorySeparatorChar + "unzip" +
               Path.DirectorySeparatorChar +
               System.Web.HttpUtility.UrlEncode(result3));
  
  byte[] byteArray =
      File.ReadAllBytes(
          GlobalClass.AppDir + Path.DirectorySeparatorChar + "unzip" +
          Path.DirectorySeparatorChar +
          System.Web.HttpUtility.UrlEncode(result3));
  
  request.ContentLength = byteArray.Length;
  Stream dataStream = request.GetRequestStream();
  
  dataStream.Write(byteArray, 0, byteArray.Length); 
  
  dataStream.Close();
  
  //This will return "OK" if successful.
  WebResponse response = request.GetResponse();
  Console.WriteLine("++ HttpWebResponse: " +
                    ((HttpWebResponse)response).StatusDescription);
  </code></pre>