cURL Proxy Examples: HTTP, SOCKS5 and Authentication

cURL can send a request through a proxy with --proxy or the short option -x. The important details are protocol, authentication, DNS behavior, timeout handling and where credentials are stored.

These examples focus on command-line cURL. They are useful for testing a proxy endpoint before using it in scripts, monitoring jobs, browser profiles or application code.

Quick answer

Use --proxy for the endpoint, --proxy-user for credentials and an explicit scheme such as http://, https://, socks5:// or socks5h://. Test one endpoint first with the Proxy Tester, then reproduce the same route in cURL.

Basic HTTP proxy example

curl --proxy http://proxy.example.com:8080 https://example.com/

This tells cURL to connect to the proxy first, then request the HTTPS target through that route. Replace the host and port with the endpoint assigned in your proxy panel.

Authenticated proxy example

curl --proxy http://proxy.example.com:8080 \
  --proxy-user "username:password" \
  https://example.com/

Use --proxy-user instead of embedding credentials inside the URL when possible. It is easier to read, safer for copy/paste and less likely to break when the password contains reserved URL characters. If authentication keeps failing, review the proxy authentication guide.

SOCKS5 and SOCKS5h examples

curl --proxy socks5://proxy.example.com:1080 https://example.com/
curl --proxy socks5h://proxy.example.com:1080 https://example.com/

socks5:// can resolve DNS locally depending on the client behavior. socks5h:// asks the SOCKS proxy to resolve the hostname remotely. That difference matters when DNS location, privacy or target reachability is being tested.

Use a config file for repeatable tests

# curl-proxy.conf
proxy = "http://proxy.example.com:8080"
proxy-user = "username:password"
connect-timeout = 10
max-time = 30
location

curl --config curl-proxy.conf https://example.com/

A config file reduces copy mistakes and keeps options consistent across checks. Protect the file permissions if it stores proxy credentials, and do not commit it to a public repository.

Timeout and diagnostic flags

curl --proxy http://proxy.example.com:8080 \
  --connect-timeout 10 \
  --max-time 30 \
  --verbose \
  https://example.com/

--connect-timeout limits the proxy connection stage. --max-time limits the full transfer. --verbose is useful for controlled troubleshooting, but it can expose hostnames and authentication flow details in logs.

Common cURL proxy errors

Symptom Likely cause Fix
407 Proxy Authentication Required Credentials are missing or wrong. Check username, password, protocol and port.
Connection timeout The proxy host or port is unreachable from the current network. Test the endpoint separately and compare firewall/network rules.
Target returns a block page The proxy works, but the destination has its own policy or reputation decision. Record status, headers and target response before changing endpoints.
DNS result differs from browser Local DNS and proxy-side DNS are being mixed. Compare socks5:// and socks5h:// behavior.

Related setup guides

Scroll to Top