How to use curl with a proxy

curl is the quickest way to prove whether a proxy works, because it shows you every step.

See plans from $75/mo ♡ Read the docs

Basic forms

curl -x http://HOST:PORT https://example.com
curl -x socks5h://HOST:PORT https://example.com
curl -x socks5h://USERNAME:PASSWORD@HOST:PORT https://example.com

Credentials separately

curl -x socks5h://HOST:PORT --proxy-user USERNAME:PASSWORD https://example.com

Handy when the password contains characters that would need escaping inside a URL.

For a whole shell session

export ALL_PROXY=socks5h://USERNAME:PASSWORD@HOST:PORT
export NO_PROXY=localhost,127.0.0.1
curl https://example.com

Reading -v output

Timing a request

curl -x socks5h://USERNAME:PASSWORD@HOST:PORT -o /dev/null -s -w 'total %{time_total}s\n' https://example.com

Questions

socks5 or socks5h?

socks5h asks the proxy to resolve the hostname, which avoids DNS leaks.

Does curl on Windows differ?

The flags are identical. In PowerShell call curl.exe so you do not get the Invoke-WebRequest alias.

Related guides

Ready for your own dedicated private mobile proxy? 🎀

Real AT&T, Verizon and T-Mobile SIMs · unlimited data · one-tap IP rotation · delivered by email or Telegram.