title: Maximum time for a request with HttpWebRequest/Invoke-WebRequest?
body: <p>I have fiddled around with both System.Net.HttpWebRequest and Invoke-WebRequest (I know that beneath it is the same code) and both gives a 500 status in the following scenario:</p>
  
  <pre><code>$response = Invoke-WebRequest 'https://httpstat.us/200?sleep=270000' -TimeoutSec 360000
  </code></pre>
  
  <p>How can this be? httpstat.us is clearly set to only wait for 4.5 min. and the timeout is way above that, but all I get is a:</p>
  
  <blockquote>
    <p>Invoke-WebRequest : 500 - The request timed out.
    The web server failed to respond within the specified time.
    At line:1 char:13
    + $response = Invoke-WebRequest '<a href="https://httpstat.us/200?sleep=270000" rel="nofollow noreferrer">https://httpstat.us/200?sleep=270000</a>'  ...
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
       eption
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand</p>
  </blockquote>
  
  <p>It seems to me, that there's a maximum timeout of the request (about 3-4 min.). Anobody knows what to do?</p>
  
  <p>I have set up this scenario because I have a website that I need to test that has a long response time.</p>