Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Proxy Authentication error

Reply
 
Old 03-02-2007   #1 (permalink)
forestial


 
 

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 SpecsSystem Spec
Old 03-02-2007   #2 (permalink)
Brandon Shell


 
 

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 SpecsSystem Spec
Old 03-02-2007   #3 (permalink)
forestial


 
 

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 SpecsSystem Spec
Old 03-02-2007   #4 (permalink)
Brandon Shell


 
 

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
news6BBE7F5-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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46