Linux 如何设置 curl 以永久使用代理?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7559103/
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-05 06:21:37  来源:igfitidea点击:

How do I set up curl to permanently use a proxy?

linuxubuntucurl

提问by Ben

How can I set up "curl" to permanently use a proxy server in the terminal?

如何设置“curl”以在终端中永久使用代理服务器?

采纳答案by Sandro Munda

You can make a alias in your ~/.bashrc file :

您可以在 ~/.bashrc 文件中创建别名:

alias curl="curl -x <proxy_host>:<proxy_port>"

Another solution is to use (maybe the better solution) the ~/.curlrcfile (create it if it does not exist) :

另一种解决方案是使用(也许是更好的解决方案)~/.curlrc文件(如果它不存在则创建它):

proxy = <proxy_host>:<proxy_port>

回答by Trevor

Curl will look for a .curlrc file in your home folder when it starts. You can create (or edit) this file and add this line:

Curl 将在启动时在您的主文件夹中查找 .curlrc 文件。您可以创建(或编辑)此文件并添加以下行:

proxy = yourproxy.com:8080

回答by Peter T

Many UNIX programs respect the http_proxyenvironment variable, curl included. The format curl accepts is [protocol://]<host>[:port].

许多 UNIX 程序尊重http_proxy环境变量,包括 curl。curl 接受的格式是[protocol://]<host>[:port].

In your shell configuration:

在您的外壳配置中:

export http_proxy http://proxy.server.com:3128

For proxying HTTPSrequests, set https_proxyas well.

对于代理 HTTP S请求,也要设置https_proxy

Curl also allows you to set this in your .curlrcfile (_curlrcon Windows), which you might consider more permanent:

Curl 还允许您在您的.curlrc文件中设置它(_curlrc在 Windows 上),您可能认为它更持久:

http_proxy=http://proxy.server.com:3128

回答by feech

One notice. On Windows, place your _curlrc in '%APPDATA%' or '%USERPROFILE%\Application Data'.

一通知。在 Windows 上,将 _curlrc 放在“%APPDATA%”或“%USERPROFILE%\Application Data”中。