wget is not using environment variable based proxy settings

tire0011 picture tire0011 · Mar 11, 2016 · Viewed 11.4k times · Source

I have a windows nano server and try to set the proxy settings. The nano server is only in command mode no GUI. I have run in PowerShell

netsh winhttp set proxy proxy-server="ipadress:8080"

then I have

ping www.google.de 

and the IP address from google was shown, so there is some connection. But when I try to run

wget www.google.de 

I get

"Unable to connect to the remote server"

then I have set the proxy in the PowerShell environment with

set http_proxy="ipadress:8080" and https_proxy...

but the same problem. When I call wget directly with the proxy settings it works:

wget 'http://www.google.de' -Proxy http://ipadress:8080

How can I get it work that wget uses the global proxy settings? Or are the settings not correctly set? Or need I to install some windows features, that it is working?

I use wget to test the connection later any web request for any program should work.

Answer

Matt picture Matt · Mar 14, 2016

Pretty sure your issue here is that you are not setting environment variables and getting mixed up between cmd exe's and PowerShell cmdlets. As we read from the (what I hope is) the documentation for wget concerning proxy information:

The standard way to specify proxy location, which Wget recognizes, is using the following environment variables:

  • http_proxy
  • https_proxy

Which is exactly what you tried to do here which was a successful operation (no error) but did not work as expected.

set http_proxy="ipadress:8080"

Problem is that if you run that in PowerShell set is an alias for Set-Variable. See Get-Alias set.

PS C:\Users\matt> Get-Variable http*

Name                           Value                                                                                        
----                           -----                                                                                        
http_proxy=ipadress:8080     

You are also having an issue with wget as that is an alias of Invoke-WebRequest. That would only be an issue if you had at least PowerShell version 3.0 which you appear to have. In your working example you are using cmdlet syntax (-Proxy ...).

In both cases (set and the non-working wget) the command was ambiguous and PowerShell had to try to match it up to something....

So what we are seeing here is about_Command_Precedence coming into play

If you do not specify a path, Windows PowerShell uses the following precedence order when it runs commands:

  1. Alias
  2. Function
  3. Cmdlet
  4. Native Windows commands

Native Windows commands is last on the list! Really though if you are in PowerShell doing this you might as well use PowerShell cmdlets to get your environment variables set (if you insist on using wget). The only thing I am not sure of is which method you should use the first here should not persist the session where the second method is permanent. Sure the first would suffice but use the second if you want to keep these set on the computer between sessions.

  1. $env:http_proxy = "ipaddress:8080"
  2. [Environment]::SetEnvironmentVariable("http_proxy", "ipaddress:8080", "Machine")

You can read more on this from TechNet. Also watch your spelling of "address"


If you are going to be using cmd utilities make sure you append .exe and if you don't specify the full path to the resource then ensure its directory is part of the path environment variable.