title: Powershell - Increase the timeout for retrieving XML from a URL
body: <p>I'm trying to retrieve an XML stream from a URL. For most URLs my code below works fine. But, I have a couple URLs that timeout. The URLs in question <b>do</b> work from Internet Explorer.</p>
  
  <pre><code>$webclient=New-Object "System.Net.WebClient"
  [xml]$data=$webclient.DownloadString($url)
  </code></pre>
  
  <p>So, I went searching for a way to increase the timeout period. From what I've read, I believe I cannot do this using <code>System.Net.WebClient</code>. I think I need to use <code>System.Net.WebRequest</code> instead, but I cannot get it to work. The code I've been working on is below:</p>
  
  <pre><code>$myHttpWebRequest = [system.net.WebRequest]::Create($url)
  $myHttpWebRequest.Timeout = 600000
  $myHttpWebResponse = $myHttpWebRequest.GetResponse()
  $sr = New-Object System.IO.StreamReader($response.GetResponseStream())
  [xml]$xml = [xml]$sr.ReadToEnd()
  </code></pre>
  
  <p>The URLs I'm trying to access are internal to my company, so I can't post them. But, they do work in IE and the actual URL should be irrelevant.</p>
  
  <p>Ideas?</p>
  
  <p>EDIT: Preliminary testing shows that adding <code>$myHttpWebRequest.AuthenticationLevel = "None"</code> works. Thanks Scott Saad.</p>