跳转到内容
Guides 1 分钟阅读 1381 次浏览

使用 cURL 配置代理

如何用 cURL 工具在命令行中使用代理:HTTP、SOCKS、身份验证与示例。

cURL CLI
使用 cURL 配置代理

使用 cURL 配置代理

cURL 是一款功能强大的 HTTP 命令行工具,对各类代理的支持都非常出色。

基本语法

curl -x [protocol://]host:port URL

HTTP 代理

# 通过代理发起简单请求
curl -x http://proxy.example.com:8080 https://httpbin.org/ip

# 带身份验证
curl -x http://user:[email protected]:8080 https://httpbin.org/ip

# 或者分开写
curl -x http://proxy.example.com:8080 -U user:password https://httpbin.org/ip

HTTPS 代理

curl -x https://proxy.example.com:8080 https://httpbin.org/ip

SOCKS 代理

# SOCKS4
curl --socks4 proxy.example.com:1080 https://httpbin.org/ip

# SOCKS4A(DNS 通过代理解析)
curl --socks4a proxy.example.com:1080 https://httpbin.org/ip

# SOCKS5
curl --socks5 proxy.example.com:1080 https://httpbin.org/ip

# SOCKS5 且 DNS 通过代理解析(推荐)
curl --socks5-hostname proxy.example.com:1080 https://httpbin.org/ip

环境变量

# 全局设置代理
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080

# 此后所有请求都会走代理
curl https://httpbin.org/ip

# 对特定主机不使用代理
export no_proxy=localhost,127.0.0.1,.internal.com

常用选项

# 显示连接耗时
curl -x http://proxy:8080 -w "Time: %{time_total}s\n" https://httpbin.org/ip

# 忽略 SSL 错误
curl -x http://proxy:8080 -k https://example.com

# 设置超时
curl -x http://proxy:8080 --connect-timeout 10 https://httpbin.org/ip

# 跟随重定向
curl -x http://proxy:8080 -L https://httpbin.org/redirect/3

# 保存 cookie
curl -x http://proxy:8080 -c cookies.txt https://example.com

# 发送 POST 请求
curl -x http://proxy:8080 -X POST -d "data=value" https://httpbin.org/post

代理列表检测脚本

#!/bin/bash
while read proxy; do
    result=$(curl -x "$proxy" -s --connect-timeout 5 https://httpbin.org/ip)
    if [ $? -eq 0 ]; then
        echo "[OK] $proxy"
    else
        echo "[FAIL] $proxy"
    fi
done < proxies.txt

调试

# 详细输出
curl -x http://proxy:8080 -v https://httpbin.org/ip

# 仅显示响应头
curl -x http://proxy:8080 -I https://httpbin.org/ip
已更新: 09.01.2026
返回分类

试用我们的代理

遍布 100+ 国家的 20,000+ 代理

support_agent
GProxy Support
Usually replies within minutes
Hi there!
Send us a message and we'll reply as soon as possible.