Using Proxies with cURL
cURL is a powerful command-line utility for HTTP. It excellently supports all proxy types.
Basic Syntax
curl -x [protocol://]host:port URL
HTTP Proxy
# Simple request through proxy
curl -x http://proxy.example.com:8080 https://httpbin.org/ip
# With authentication
curl -x http://user:password@proxy.example.com:8080 https://httpbin.org/ip
# Or separately
curl -x http://proxy.example.com:8080 -U user:password https://httpbin.org/ip
HTTPS Proxy
curl -x https://proxy.example.com:8080 https://httpbin.org/ip
SOCKS Proxy
# SOCKS4
curl --socks4 proxy.example.com:1080 https://httpbin.org/ip
# SOCKS4A (DNS through proxy)
curl --socks4a proxy.example.com:1080 https://httpbin.org/ip
# SOCKS5
curl --socks5 proxy.example.com:1080 https://httpbin.org/ip
# SOCKS5 with DNS through proxy (recommended)
curl --socks5-hostname proxy.example.com:1080 https://httpbin.org/ip
Environment Variables
# Set proxy globally
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
# Now all requests go through proxy
curl https://httpbin.org/ip
# Ignore proxy for certain hosts
export no_proxy=localhost,127.0.0.1,.internal.com
Useful Options
# Show connection time
curl -x http://proxy:8080 -w "Time: %{time_total}s\n" https://httpbin.org/ip
# Ignore SSL errors
curl -x http://proxy:8080 -k https://example.com
# Set timeout
curl -x http://proxy:8080 --connect-timeout 10 https://httpbin.org/ip
# Follow redirects
curl -x http://proxy:8080 -L https://httpbin.org/redirect/3
# Save cookies
curl -x http://proxy:8080 -c cookies.txt https://example.com
# Send POST request
curl -x http://proxy:8080 -X POST -d "data=value" https://httpbin.org/post
Proxy List Check Script
#!/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
Debugging
# Verbose output
curl -x http://proxy:8080 -v https://httpbin.org/ip
# Show only headers
curl -x http://proxy:8080 -I https://httpbin.org/ip
Обновлено: 09.01.2026
Назад к категории