Integrations

Using proxies with curl: auth, SOCKS5 and testing

Use proxies with curl: copy-paste commands for HTTP and SOCKS5 proxies with authentication, verbose debugging, timing checks, environment variables and Windows.

3 min read Updated

On this page

curl is the quickest way to check that a proxy works and to see exactly where a problem comes from. Every command below uses the values from your dashboard in place of USERNAME, PASSWORD, HOST and PORT.

Basic request

curl -x "http://USERNAME:PASSWORD@HOST:PORT" https://api.ipify.org

-x is short for --proxy. The command prints the exit IP address. Run it without -x to compare it with your own IP.

The http:// at the start describes the connection to the proxy. HTTPS websites still work, because curl opens an encrypted tunnel through the proxy.

Credentials as a separate option

curl -x "http://HOST:PORT" -U "USERNAME:PASSWORD" https://api.ipify.org

-U is short for --proxy-user. This form keeps the credentials out of the URL, so characters like @ or # in a password don't need percent-encoding. curl splits the value at the first colon, so the username itself can't contain one.

SOCKS5

curl -x "socks5h://USERNAME:PASSWORD@HOST:PORT" https://api.ipify.org

Use the SOCKS5 port from your dashboard. With socks5h://, the proxy resolves domain names. With socks5://, curl resolves them on your machine first. HTTP and SOCKS5 explains why the difference matters.

See what's happening

Add -v to watch the conversation with the proxy:

curl -v -x "http://USERNAME:PASSWORD@HOST:PORT" https://example.com -o /dev/null

Read the output in order:

  1. > CONNECT example.com:443 is curl asking the proxy for a tunnel.
  2. The proxy's answer comes next. A 200 status means the proxy accepted your credentials and connected. A 407 means it rejected them.
  3. After that come the TLS handshake with the website and the website's own response.

So a 403 or 429 that appears after the tunnel was set up comes from the website, not from the proxy. On Windows, use -o NUL instead of -o /dev/null.

Verbose output includes the Proxy-Authorization header, which is your username and password in base64. Remove that line before you share a log with anyone, including our support team.

Measure speed

curl -s -o /dev/null -x "http://USERNAME:PASSWORD@HOST:PORT" \
  -w "connect: %{time_connect}s  tls: %{time_appconnect}s  first byte: %{time_starttransfer}s  total: %{time_total}s  status: %{http_code}\n" \
  https://example.com

connect is the time to reach the proxy. tls adds setting up the tunnel and the handshake with the website. first byte is when the website started to answer. Run the command a few times, because residential IPs vary from one to the next. The proxy speed test gives you the same kind of numbers without a terminal.

Timeouts and retries

curl --connect-timeout 10 --max-time 30 --retry 2 \
  -x "http://USERNAME:PASSWORD@HOST:PORT" https://example.com

--connect-timeout limits the connection phase, which includes reaching the proxy. --max-time limits the whole request. --retry repeats the request after transient errors such as timeouts and 429, 500, 502, 503 or 504 responses.

Several requests in a row

Each curl run opens a new connection, so on a rotating line every run can show a different IP:

for i in 1 2 3 4 5; do
  curl -s -x "http://USERNAME:PASSWORD@HOST:PORT" https://api.ipify.org
  echo
done

With a sticky line, the same loop should print the same IP each time. Rotating vs sticky sessions explains both modes.

Environment variables

curl and many other programs read proxy settings from the environment:

export http_proxy="http://USERNAME:PASSWORD@HOST:PORT"
export https_proxy="http://USERNAME:PASSWORD@HOST:PORT"
export no_proxy="localhost,127.0.0.1"
curl https://api.ipify.org

curl reads http_proxy only in lowercase; the other variables work in either case. Every program you start from that shell may now use the proxy, so clear the variables when you're done:

unset http_proxy https_proxy no_proxy

Windows

Windows 10 and 11 include curl. In Windows PowerShell, type curl.exe, because curl there can be an alias for a different command:

curl.exe -x "http://USERNAME:PASSWORD@HOST:PORT" https://api.ipify.org

To set the proxy for the current PowerShell session:

$env:HTTPS_PROXY = "http://USERNAME:PASSWORD@HOST:PORT"
curl.exe https://api.ipify.org

Common curl errors

Error Likely cause
(56) CONNECT tunnel failed, response 407 Wrong or incomplete username or password
(7) Failed to connect to HOST port PORT Wrong host or port, or a firewall blocks the port
(28) Connection timed out or Operation timed out The proxy or the website didn't answer in time
(35) with wrong version number https:// in front of a plain proxy port; use http://
(97) with a SOCKS message Wrong SOCKS5 credentials, or a SOCKS client pointed at a port that isn't SOCKS5

Older curl versions word some of these messages differently. Troubleshooting covers each case in more detail.