Skip to main content

4 min read

cURL Proxy: What It Is and How to Use It (Commands and Examples)

Close-up of the Command key on a keyboard

A cURL proxy is simply a proxy server that the cURL command-line tool sends its requests through. You set it with the -x (or --proxy) option, or with environment variables, and cURL then connects to websites through the proxy’s IP address instead of yours. This guide shows the commands you’ll actually use: HTTP and SOCKS5 proxies, authentication, country targeting, environment variables, debugging and timing.

Want residential IPs to test with cURL? Get a trial on QuickProxy for only $1.99.

The basic command

curl -x http://gate.quickproxy.io:8000 -U "USERNAME:PASSWORD" https://httpbin.org/ip
  • -x sets the proxy (host and port). The scheme says how cURL talks to the proxy: http://, https://, socks5:// or socks5h://.
  • -U (--proxy-user) passes the proxy username and password.
  • The response shows the IP address the website sees. It should be the proxy’s, not yours.

For HTTPS websites, cURL asks the proxy to open a tunnel (the CONNECT method), so your connection to the website stays encrypted end to end.

Choosing a country

With Quick Proxy, you choose the exit country by adding a country code to the username:

curl -x http://gate.quickproxy.io:8000 -U "USERNAME-cc-de:PASSWORD" https://httpbin.org/ip
curl -x http://gate.quickproxy.io:8000 -U "USERNAME-cc-jp:PASSWORD" https://httpbin.org/ip

See the available locations, and the authentication guide for other options.

The cURL proxy options you’ll use most

Option What it does
-x, --proxy [scheme://]host:port Sets the proxy
-U, --proxy-user user:pass Proxy credentials (kept out of the URL)
--socks5-hostname host:port SOCKS5 with DNS resolved at the proxy (same as socks5h://)
--noproxy host1,host2 Hosts that should bypass the proxy
-p, --proxytunnel Forces a CONNECT tunnel even for plain HTTP requests
-v Verbose output: shows the proxy connection, CONNECT and response headers
-w "..." Prints timings and status codes after the request
--connect-timeout N, -m N Limits connection time and total time

SOCKS5 proxies

curl -x socks5h://gate.quickproxy.io:8000 -U "USERNAME-cc-fr:PASSWORD" https://httpbin.org/ip

Use socks5h rather than socks5, so that the website’s address is resolved by the proxy, in the proxy’s location, not by your own DNS. SOCKS5 doesn’t add encryption; HTTPS does that. See how SOCKS proxies differ.

Setting a proxy with environment variables

cURL, and many other tools, read these variables:

# macOS / Linux
export https_proxy="http://gate.quickproxy.io:8000"
export http_proxy="http://gate.quickproxy.io:8000"
export no_proxy="localhost,127.0.0.1,.internal.example"
curl -U "USERNAME-cc-us:PASSWORD" https://httpbin.org/ip

# Windows PowerShell (curl.exe)
$env:HTTPS_PROXY = "http://gate.quickproxy.io:8000"
curl.exe -U "USERNAME-cc-us:PASSWORD" https://httpbin.org/ip

Variables are handy for proxying a whole script, but they affect every tool that reads them. Remove them when you’re done: unset https_proxy http_proxy. On Windows, use curl.exe, because in older PowerShell versions curl is an alias for a different command.

Debugging and measuring

To see exactly what happens, add -v. You’ll see the connection to the proxy, the CONNECT request and the status codes from both the proxy and the website.

To measure speed:

curl -s -o /dev/null -x http://gate.quickproxy.io:8000 -U "USERNAME:PASSWORD" \
  -w "status %{http_code}  connect %{time_connect}s  first byte %{time_starttransfer}s  total %{time_total}s\n" \
  https://example.com/

Run it several times, because each request may use a different residential IP. See what affects proxy speed.

Common cURL proxy errors

  • 407 Proxy Authentication Required: wrong username or password, or special characters in the password breaking the command. Quote the -U value.
  • Could not resolve proxy: a typo in the proxy host, or no network access.
  • Connection timed out: a firewall blocking the proxy port, or a slow target. Add --connect-timeout and retry.
  • Proxy CONNECT aborted, or 502: the proxy couldn’t reach the website. Retry, or try another location.
  • Same IP every time: you may be using a sticky session. Rotating sessions give a new IP per connection.

For a full list, see the 10 most common proxy errors.

Practical uses

  • Quickly test that a proxy works, and which country it exits in.
  • Check how a page or API responds to requests from another country.
  • Test redirects and headers your site sends to different markets.
  • Prototype requests before writing a script. When you move to code, see wget and Python with concurrent connections.

Collect only public data and respect each site’s terms and rate limits. See legal web scraping.

Conclusion

Using a proxy with cURL takes one option, -x, plus -U for credentials. Use socks5h:// for SOCKS with remote DNS, environment variables to proxy whole scripts, -v to debug and -w to measure. Add a country code to the username to test from any market.

Test the commands with residential IPs: start a $1.99 trial.

Questions and Answers

Q1: How do I use a proxy with cURL?

A1: Add -x http://host:port to your command, and -U "user:pass" if the proxy needs a login.

Q2: What is the difference between socks5 and socks5h in cURL?

A2: With socks5h, the proxy resolves the website’s hostname. With socks5, your machine does. socks5h is usually what you want.

Q3: How do I make cURL ignore the proxy for some hosts?

A3: Use --noproxy host1,host2, or set the no_proxy environment variable.

Q4: Why do I get a 407 error?

A4: The proxy rejected your credentials. Check the username and password, and put the -U value in quotes.

Related reading

Put the article into practice.

Spin up real residential IPs in 150+ countries. Pay once or subscribe — from $11.