Linux 如何为 wget 设置代理?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11211705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:04:28  来源:igfitidea点击:

How to set proxy for wget?

linuxproxywget

提问by Hakim

I want to download something with wgetusing a proxy:

我想wget使用代理下载一些东西:

HTTP Proxy: 127.0.0.1
Port: 8080

The proxy does not need username and password.

代理不需要用户名和密码。

How can I do this?

我怎样才能做到这一点?

回答by hovanessyan

the following possible configs are located in /etc/wgetrcjust uncomment and use...

以下可能的配置位于/etc/wgetrc只是取消注释和使用...

# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/

# If you do not want to use proxy at all, set this to off.
#use_proxy = on

回答by amaksr

For all users of the system via the /etc/wgetrcor for the user only with the ~/.wgetrcfile:

对于系统的所有用户,通过/etc/wgetrc或 仅对于具有~/.wgetrc文件的用户:

use_proxy=yes
http_proxy=127.0.0.1:8080
https_proxy=127.0.0.1:8080

or via -eoptions placed after the URL:

或通过-e放置在 URL 之后的选项:

wget ... -e use_proxy=yes -e http_proxy=127.0.0.1:8080 ...

回答by shivshnkr

Type in command line :

在命令行中输入:

$ export http_proxy=http://proxy_host:proxy_port

for authenticated proxy,

对于经过身份验证的代理,

$ export http_proxy=http://username:password@proxy_host:proxy_port

and then run

然后运行

$ wget fileurl

for https, just use https_proxy instead of http_proxy. You could also put these lines in your ~/.bashrc file so that you don't need to execute this everytime.

对于 https,只需使用 https_proxy 而不是 http_proxy。你也可以把这些行放在你的 ~/.bashrc 文件中,这样你就不需要每次都执行它。

回答by juan_liga

wget uses environment variables somthing like this at command line can work:

wget 在命令行中使用环境变量这样的东西可以工作:

export http_proxy=http://your_ip_proxy:port/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export dns_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

回答by fiat

In Windows - for Fiddler say - using environment variables:

在 Windows 中 - 对于 Fiddler 来说 - 使用环境变量:

set http_proxy=http://127.0.0.1:8888
set https_proxy=http://127.0.0.1:8888

回答by Rahul Das

In my ubuntu, following lines in $HOME/.wgetrc did the trick!

在我的 ubuntu 中,$HOME/.wgetrc 中的以下几行就成功了!

http_proxy = http://uname:[email protected]:8080

use_proxy = on

http_proxy = http://uname:[email protected]:8080

use_proxy = on

回答by a1an

In Debian Linux wget can be configured to use a proxy both via environment variables and via wgetrc. In both cases the variable names to be used for HTTP and HTTPS connections are

在 Debian Linux 中,wget 可以配置为通过环境变量和 wgetrc 使用代理。在这两种情况下,用于 HTTP 和 HTTPS 连接的变量名称都是

http_proxy=hostname_or_IP:portNumber
https_proxy=hostname_or_IP:portNumber

Note that the file /etc/wgetrc takes precedence over the environment variables, hence if your system has a proxy configured there and you try to use the environment variables, they would seem to have no effect!

请注意,文件 /etc/wgetrc 优先于环境变量,因此如果您的系统在那里配置了代理并且您尝试使用环境变量,它们似乎不起作用!

回答by B E

In Ubuntu 12.x, I added the following lines in $HOME/.wgetrc

在 Ubuntu 12.x 中,我在 $HOME/.wgetrc 中添加了以下几行

http_proxy = http://uname:[email protected]:8080

use_proxy = on

http_proxy = http://uname:[email protected]:8080

use_proxy = on

回答by Janderson Silva

After trying many tutorials to configure my Ubuntu 16.04 LTS behind a authenticated proxy, it worked with these steps:

在尝试了许多教程在经过身份验证的代理后面配置我的 Ubuntu 16.04 LTS 之后,它使用以下步骤:

Edit /etc/wgetrc:

编辑/etc/wgetrc

$ sudo nano /etc/wgetrc

Uncomment these lines:

取消注释这些行:

#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/
#use_proxy = on

Change http://proxy.yoyodyne.com:18023/to http://username:password@domain:port/

更改http://proxy.yoyodyne.com:18023/http://username:password@domain:port/

IMPORTANT: If it still doesn't work, check if your password has special characters, such as #, @, ... If this is the case, escape them (for example, replace passw@rdwith passw%40rd).

重要提示:如果仍然无效,请检查您的密码是否包含特殊字符,例如#, @, ... 如果是这种情况,请将它们转义(例如,替换passw@rdpassw%40rd)。

回答by rashok

export http_proxy=http://proxy_host:proxy_port/
export https_proxy=https://proxy_host:proxy_port/

or

或者

export http_proxy=http://username:password@proxy_host:proxy_port/
export https_proxy=https://username:password@proxy_host:proxy_port/

As all others explained here, these environment variable helps to pass on proxies.

正如此处所有其他人所解释的那样,这些环境变量有助于传递代理。

Note:But please not that if the password contains any special character then that needs to be configured as %<hex_value_of_special_char>.

注意:但请注意,如果密码包含任何特殊字符,则需要将其配置为%<hex_value_of_special_char>.

Example:If the password is pass#123, need to be used as pass%23123in above export commands.

示例:如果密码为pass#123,则需要按照pass%23123上述导出命令使用。