curl Proxy: How to Use a Proxy with curl (With Examples)

To use a proxy with curl, add -x (or --proxy) followed by the proxy address:

curl -x http://user:pass@proxy-host:port https://api.ipify.org

If the command prints the proxy’s address rather than yours, it works. Because curl is so simple and shows exactly what happens, it is also the best tool for checking whether a proxy works before you debug your own code. This guide covers the options you will actually use, and how to read the errors.

New to proxies? See what a proxy server is first.

The -x option

The general form is:

curl -x [scheme://][user:pass@]host:port  URL

Some everyday examples:

# Check your outgoing address through the proxy
curl -x http://proxy-host:port https://api.ipify.org

# Fetch only the response headers of a page
curl -x http://proxy-host:port -I https://example.com

# Save a page to a file
curl -x http://proxy-host:port -o page.html https://example.com

If you leave out the scheme, curl assumes an HTTP proxy. If you leave out the port, it uses 1080 — usually not what you want, so always include the port.

HTTP, SOCKS5 and socks5h

Proxy address starts with Meaning
http:// An ordinary HTTP proxy. Works for both http and https websites. The most common choice.
socks5:// SOCKS5 proxy; your machine looks up the website’s address.
socks5h:// SOCKS5 proxy; the proxy looks up the address (remote DNS). Better for location-sensitive work.
https:// The connection to the proxy is itself encrypted. Only use this if your provider says the proxy supports it.

A frequent mistake is writing https://proxy-host because the website is HTTPS. The scheme describes the proxy, not the website. For most providers, use http://. For the difference between the protocols, see HTTP vs SOCKS5 proxy.

Username and password

You can put the login in the address, or pass it separately with -U (--proxy-user):

curl -x http://proxy-host:port -U user:pass https://api.ipify.org

The separate form is easier when the password contains special characters such as @ or :, which would otherwise break the address. Wrap it in quotes so your shell does not interpret characters like ! or $:

curl -x http://proxy-host:port -U 'user:p@ss$word' https://api.ipify.org

Typing the password on the command line saves it in your shell history. For anything beyond a quick test, put it in an environment variable or a config file (below) instead. If your provider uses an IP allow-list, you need no login at all.

Environment variables

curl also picks up a proxy from environment variables, so you do not need -x on every command:

export http_proxy="http://user:pass@proxy-host:port"
export https_proxy="http://user:pass@proxy-host:port"
curl https://api.ipify.org
  • http_proxy must be lowercase — curl ignores the uppercase version for security reasons.
  • https_proxy (or HTTPS_PROXY) covers https websites.
  • all_proxy covers everything, and is handy for SOCKS5: export all_proxy="socks5h://proxy-host:port".
  • An explicit -x always wins over the variables.

Other tools — Python, Git, package managers — read the same variables, which is why setting them is the usual way to proxy a whole terminal session.

Skipping the proxy for some hosts

To make certain hosts go direct, use --noproxy or the no_proxy variable:

curl --noproxy "localhost,127.0.0.1,.internal.example.com" -x http://proxy-host:port https://intranet.internal.example.com

export no_proxy="localhost,127.0.0.1,.internal.example.com"

To ignore every proxy setting for one command — useful for comparing “with” and “without” — use --noproxy "*".

Making it permanent with .curlrc

curl reads a config file at start-up: ~/.curlrc on macOS and Linux, %APPDATA%\_curlrc on Windows. Add:

proxy = "http://proxy-host:port"
proxy-user = "user:pass"

Now every curl command uses the proxy. Remember it is there — a forgotten .curlrc is a classic reason for “curl behaves differently on my machine”. Use curl -q to skip the file for one command.

curl on Windows

Windows 10 and 11 include real curl as curl.exe. In Windows PowerShell 5.1, plain curl is a shortcut for a different command (Invoke-WebRequest) that does not understand -x. So type curl.exe:

curl.exe -x http://user:pass@proxy-host:port https://api.ipify.org

To set variables in PowerShell for the current window:

$env:https_proxy = "http://user:pass@proxy-host:port"

curl does not read the proxy you set in Windows Settings. See Windows proxy settings for which tools do; Mac users can see Mac proxy settings.

Seeing what happens with -v

Add -v (verbose) to see each step. Through an HTTP proxy to an HTTPS site, look for lines like:

* Connected to proxy-host (203.0.113.10) port 8080
> CONNECT example.com:443 HTTP/1.1
< HTTP/1.1 200 Connection established
* CONNECT tunnel established

This tells you where things break: if you never see “Connected to proxy-host”, the proxy is unreachable; if CONNECT gets a status other than 200, the proxy refused the tunnel; if the tunnel is established but the page fails, the problem is with the website, not the proxy. You will also see a Proxy-Authorization line — do not paste that into public forums, as it contains your login.

Common errors and what they mean

Message Meaning and fix
Could not resolve proxy The proxy host name is wrong or DNS failed. Check spelling.
Failed to connect to proxy-host port … Wrong port, proxy down, or a firewall in the way.
Received HTTP code 407 from proxy after CONNECT Login refused: wrong username or password, or your IP is not allow-listed.
Proxy CONNECT aborted / connection reset Often a protocol mismatch, such as SOCKS5 details used with http://.
SSL: wrong version number Proxy written as https:// but it speaks plain HTTP. Use http://.
Command works but shows your own address A no_proxy entry, uppercase HTTP_PROXY, or plain curl in PowerShell 5.1.

Avoid “fixing” SSL errors with -k (--insecure); it turns off certificate checks for the website. Correct the proxy address instead.

Using YiluProxy with curl

All five YiluProxy lines provide a host, port and login that work directly with -x, over HTTP or SOCKS5: rotating residential, static residential, rotating datacenter, static datacenter and mobile. A one-line curl check is the quickest way to confirm a trial proxy works before you wire it into code — for Python, see Python requests proxy.

A proxy changes where requests come from; it does not change any website’s rules. Use it for publicly visible pages and your own assets.

FAQ

Q1. What does -x mean in curl?

A. It sets the proxy to use: -x http://host:port. The long form is --proxy.

Q2. How do I use a SOCKS5 proxy with curl?

A. Use -x socks5h://host:port. The h makes the proxy do the DNS lookup, which keeps location-dependent results consistent.

Q3. Why does curl ignore my HTTP_PROXY variable?

A. curl only reads the lowercase http_proxy for http websites. Use lowercase, or pass -x directly.

Q4. Does curl use the system proxy settings?

A. No. It uses -x, environment variables or .curlrc, not the Windows or Mac proxy panel.


Test first, then buy

One curl command is enough to check a trial proxy against your own target pages.

Start a free trial

(Examples reflect current curl behaviour. They contain no pool-size, success-rate or performance figures, as those vary by provider, target and time. Written November 2026.)

Scroll to Top