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
How do I set up curl to permanently use a proxy?
提问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 ~/.curlrc
file (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_proxy
environment 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_proxy
as well.
对于代理 HTTP S请求,也要设置https_proxy
。
Curl also allows you to set this in your .curlrc
file (_curlrc
on 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”中。