![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Proxy Authentication error I am encountering an error like: Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (407) Proxy Authentication Required." when trying to do the following: $wc = new-object System.Net.WebClient $wc.DownloadFile($wsdlLocation, $wsdlPath) (code borrowed from Lee Holmes's blog on calling web services) I'm speculating that this means my employer's proxy server is expecting some kind of credentials to accompany the HTTP GET, and this code not providing them. Web browsers, both IE and Firefox running on the same machine, have no problems accessing the web. Presumably they are somehow using credentials for the logged-in user and passing them with the request(?) - I don't know how this stuff works. I spent a bit of time reading help on get-credential but couldn't see how to link the object this returns to the DownloadFile() call. Does anyone know how to do this? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Proxy Authentication error Try this: PS> $proxy = New-Object System.Net.WebProxy("http://myproxy:80") PS> $wc.proxy = $proxy If it still ask for creds then you can set the proxy credentials property. $proxy | gm "forestial" <forestial@discussions.microsoft.com> wrote in message news:95174F08-7CB4-4316-ADA5-4B5C3C6E0D18@microsoft.com... >I am encountering an error like: > Exception calling "DownloadFile" with "2" argument(s): "The remote server > returned an error: (407) Proxy Authentication Required." > > when trying to do the following: > $wc = new-object System.Net.WebClient > $wc.DownloadFile($wsdlLocation, $wsdlPath) > (code borrowed from Lee Holmes's blog on calling web services) > > I'm speculating that this means my employer's proxy server is expecting > some > kind of credentials to accompany the HTTP GET, and this code not providing > them. Web browsers, both IE and Firefox running on the same machine, > have > no problems accessing the web. Presumably they are somehow using > credentials > for the logged-in user and passing them with the request(?) - I don't know > how this stuff works. > > I spent a bit of time reading help on get-credential but couldn't see how > to > link the object this returns to the DownloadFile() call. > > Does anyone know how to do this? > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Proxy Authentication error Thanks Brandon. I got it to work as follows (using a slightly different example): $cred = get-credential #puts up username and password prompt dialog $wfeed = "http://xml.weather.yahoo.com/forecastrss?p=78750" $proxy = New-Object System.Net.WebProxy("http://inetproxy:80") # our proxy server $proxy.credentials = $cred.GetNetworkCredential(); $wc = new-object System.Net.WebClient $wc.proxy = $proxy $rssdata = [xml]$wc.DownloadString($wfeed) The call to GetNetworkCredential() is needed because the object returned by get-credential is a System.Management.Automation.PSCredential, but we need a regular System.Net.NetworkCredential to give to the $proxy. That username/password prompt is bothersome if you are running this frequently. I suppose I can store the credentials in a global variable first time up, and then avoid re-issuing the get-credential cmdlet call subsequently. One problem that's already apparent with that notion is that the object returned by $cred.GetNetworkCredential() has a 'password' member, which reveals the password entered to get-credential in plain text!! So it's probably not good to keep that thing around longer than needed. I wonder if there is a way to obtain the credential of the currently logged in user, without prompting? It would seem that the web browsers must be doing this all the time since they are able to satisfy the proxy server without prompting me. "Brandon Shell" wrote: > Try this: > > PS> $proxy = New-Object System.Net.WebProxy("http://myproxy:80") > PS> $wc.proxy = $proxy > > If it still ask for creds then you can set the proxy credentials property. > $proxy | gm > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Proxy Authentication error Im glad you got it working... I was aware that you needed ICredentials, but some people like to figure that stuff out on thier own ![]() You can use the creds of the current user and actually I think that is much simpler. $proxy = New-Object System.Net.WebProxy("http://inetproxy:80") $proxy.UseDefaultCredentials = $true "forestial" <forestial@discussions.microsoft.com> wrote in message news 6BBE7F5-4684-4EB2-ADC1-D38C4A193E27@microsoft.com...> Thanks Brandon. I got it to work as follows (using a slightly different > example): > > $cred = get-credential #puts up username and password prompt dialog > > $wfeed = "http://xml.weather.yahoo.com/forecastrss?p=78750" > > $proxy = New-Object System.Net.WebProxy("http://inetproxy:80") # our > proxy > server > $proxy.credentials = $cred.GetNetworkCredential(); > $wc = new-object System.Net.WebClient > $wc.proxy = $proxy > > $rssdata = [xml]$wc.DownloadString($wfeed) > > The call to GetNetworkCredential() is needed because the object returned > by > get-credential is a System.Management.Automation.PSCredential, but we need > a > regular System.Net.NetworkCredential to give to the $proxy. > > That username/password prompt is bothersome if you are running this > frequently. I suppose I can store the credentials in a global variable > first > time up, and then avoid re-issuing the get-credential cmdlet call > subsequently. > > One problem that's already apparent with that notion is that the object > returned by $cred.GetNetworkCredential() has a 'password' member, which > reveals the password entered to get-credential in plain text!! So it's > probably not good to keep that thing around longer than needed. > > I wonder if there is a way to obtain the credential of the currently > logged > in user, without prompting? It would seem that the web browsers must be > doing this all the time since they are able to satisfy the proxy server > without prompting me. > > > "Brandon Shell" wrote: > >> Try this: >> >> PS> $proxy = New-Object System.Net.WebProxy("http://myproxy:80") >> PS> $wc.proxy = $proxy >> >> If it still ask for creds then you can set the proxy credentials >> property. >> $proxy | gm >> > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| 407 Proxy Authentication Required | Vista General | |||
| Vista Defender WSUS and Proxy Authentication | Vista General | |||
| Proxy Authentication | Vista networking & sharing | |||
| Proxy authentication required error when calling wsdl.exe | PowerShell | |||