我有这个代理地址:125.119.175.48:8909
如何使用cURL(如cURL http://www.example.com)执行HTTP请求,但指定我的网络的代理地址?
我有这个代理地址:125.119.175.48:8909
如何使用cURL(如cURL http://www.example.com)执行HTTP请求,但指定我的网络的代理地址?
当前回答
如果您只是为一次性命令设置代理,则不需要导出http[s]_proxy shell变量。如。
http_proxy=http://your.proxy.server:port curl http://www.example.com
也就是说,如果我知道我总是要使用代理,我更喜欢curl -x。
其他回答
来自man curl:
-x, --proxy <[protocol://][user:password@]proxyhost[:port]>
Use the specified HTTP proxy.
If the port number is not specified, it is assumed at port 1080.
总结一下所有提到的答案:
curl -x http://<user>:<pass>@<proxyhost>:<port>/ -o <filename> -L <link>
注意,如果你正在使用SOCKS代理,而不是HTTP/HTTPS代理,你将需要使用——socks5开关:
curl --socks5 125.119.175.48:8909 http://example.com/
还可以使用——socks5-hostname代替——socks5在代理端解析DNS。
curl -x socks5://username:password@ip:port example.com
与代理认证我使用:
curl -x <protocol>://<user>:<password>@<host>:<port> --proxy-anyauth <url>
因为,我不知道为什么curl不使用/catch http[s]_proxy环境变量。