Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access web using Powershell and Proxy

I can't seem to get access to a webpage using Powershell. I keep getting a "(407) Proxy Authentication Required". I've tried many things. I don't know what the proxy is or what kind of authentication it requires. The only thing I have access to is in IE it uses a script for configuring. I tried using some IPs from that, but no luck. Any ideas?

Here is one example of what I tried:

$wc = New-Object System.Net.WebClient $wc.Headers.Add("User-Agent","Mozilla/4.0+")         $wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy $wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials $wc.DownloadString("http://stackoverflow.com") 
like image 918
user1612851 Avatar asked Jan 10 '13 17:01

user1612851


People also ask

Does PowerShell use system proxy?

The fact is that Powershell (or rather, the . NET class System. Net. WebClient, which these cmdlets used to access external resources over HTTP/HTTPS) does not use the proxy server settings specified in the user settings.

Does invoke WebRequest use proxy?

Beginning in PowerShell 7.0, Invoke-WebRequest supports proxy configuration defined by environment variables.

Does test Netconnection use proxy?

Test-NetConnect should use your proxy server if its correctly configured without having to specifically specify it. What error are you getting from the command? If this is like other powershell cmdlets, you can configure the System.


1 Answers

I had a similar issue and resolved it with just two lines of powershell:

$browser = New-Object System.Net.WebClient $browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials  

Hope this helps.

like image 143
Steve Avatar answered Nov 20 '22 00:11

Steve