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 do work from Internet Explorer.
$webclient=New-Object "System.Net.WebClient"
[xml]$data=$webclient.DownloadString($url)
So, I went searching for a way to increase the timeout period. From what I've read, I believe I cannot do this using System.Net.WebClient. I think I need to use System.Net.WebRequest instead, but I cannot get it to work. The code I've been working on is below:
$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()
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.
Ideas?
EDIT: Preliminary testing shows that adding $myHttpWebRequest.AuthenticationLevel = "None" works. Thanks Scott Saad.