Back to blog. Article language: BN EN ES FR HI ID PT RU UR VI ZH

curl proxy: how to use curl with HTTP, HTTPS and SOCKS5

To Run curl with proxy settings, add -x (or --proxy) and the proxy URL. The scheme in that URL sets the protocol: http://, https:// or socks5://. Then check the exit IP with a public IP service. New to the tool? Read our curl basics guide.

curl -x http://USER:[email protected]:8080 https://api.ipify.org

What you need before using curl with a proxy

Before you make curl use proxy servers, check your build and the connection details. In curl --version, Features should list HTTPS-proxy.

curl --version

Your provider gives you five values:

FieldExampleWhere to find
Hostproxy.example.comDashboard
Port8080, 1080Next to host
Protocolhttp, socks5Plan settings
UsernameUSERAccount page
PasswordPASSAccount page

curl proxy syntax: the -x and --proxy options

The curl --proxy option (short form -x) takes a URL. Without a scheme, curl assumes http://.

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

The options you will use most:

OptionWhat it does
-x, --proxySets the proxy URL
-U, --proxy-userPasses credentials
--socks5SOCKS5, local DNS
--socks5-hostnameSOCKS5, DNS on proxy
--noproxySkips proxy for listed hosts
--proxy-insecureSkips proxy TLS check

Need a curl proxy example with a request body? The same flag works with POST requests.

How to use curl with an HTTP or HTTPS proxy

For a curl HTTP proxy, start the URL with http://. Use https:// only if the proxy itself speaks TLS.

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

For HTTPS sites, the proxy opens a CONNECT tunnel, so traffic stays encrypted.

A curl HTTPS proxy also encrypts your hop to the proxy. Self-signed certificate in tests? Add --proxy-insecure.

How to use curl with a SOCKS5 proxy

A curl SOCKS5 proxy uses the same -x option with a SOCKS scheme. Add h to resolve DNS on the proxy.

curl -x socks5h://USER:[email protected]:1080 https://example.com
curl --socks5-hostname proxy.example.com:1080 https://example.com

Where each scheme resolves hostnames:

SchemeWhere DNS is resolvedWhen to use
socks4LocalLegacy servers
socks4aProxyLegacy, remote DNS
socks5LocalInternal hosts
socks5hProxyGeo tests
  • 💡 Pick the h variant for geo tests: DNS and IP share one location.

A curl SOCKS5 proxy also carries FTP, SMTP and other non-HTTP traffic.

Choosing a curl SOCKS proxy or HTTP? See our HTTP vs SOCKS5 comparison.

Proxy authentication in curl

curl proxy authentication takes credentials in the URL or via -U, for HTTP and SOCKS5 alike.

curl -x http://USER:[email protected]:8080 https://example.com
read -rs AUTH; curl -x proxy.example.com:8080 -U "$AUTH" https://example.com

URL-encode special characters: @ becomes %40. Bad credentials return 407 Proxy Authentication Required.

  • ❌ Don't type passwords inline: shell history keeps them. Use a variable or config file.

How to set a proxy with environment variables

curl proxy environment variables cover the whole shell; -x overrides them.

export http_proxy="http://proxy.example.com:8080"  # Linux/macOS
export https_proxy="$http_proxy"
$env:HTTPS_PROXY="http://proxy.example.com:8080"   # PowerShell

What each variable covers:

VariableApplies to
http_proxyHTTP, lowercase only
https_proxy / HTTPS_PROXYHTTPS
ALL_PROXYOther protocols
NO_PROXYHosts to bypass

For HTTP, curl ignores the uppercase name: CGI servers may set it from a header.

How to save proxy settings in .curlrc

A .curlrc file stores default options for every run.

# ~/.curlrc, Windows: %USERPROFILE%\_curlrc
proxy = "http://proxy.example.com:8080"
proxy-user = "USER:PASS"

To skip the file once, make -q the first option.

  • 💡 Run chmod 600 on it: the file stores proxy credentials for every curl call.

How to bypass the proxy: curl no proxy

The curl no proxy options send chosen requests directly, for example to localhost.

curl --noproxy "*" https://example.com
curl --noproxy "localhost,.corp" http://localhost
export NO_PROXY="localhost,127.0.0.1"
curl -x "" https://example.com

Scope of each method:

MethodScope
--noproxy "*"One command, all hosts
--noproxy listOne command, listed hosts
Environment variableShell session
-x ""One command, ignores env

How to check that curl is using the proxy

Compare IPs with and without the proxy, then read the handshake.

  1. Get your real IP from api.ipify.org.
  2. Repeat the request through the proxy.
  3. Add -v and find CONNECT or SOCKS5 lines in the verbose output.
  4. Check the new IP's country.

curl -v -x socks5h://proxy.example.com:1080 https://api.ipify.org

Signs of a working setup:

What to checkExpected result
Exit IPDiffers from yours
-v, HTTP proxyCONNECT host:443, then 200
curl SOCKS5 run, -vSOCKS5 connect, remotely resolved
CountryAs ordered

Practice case: a QA engineer compared a store API's shipping options via California and Texas IPs and caught a caching bug.

Common curl proxy errors and how to fix them

Most failures return an exit code that names the cause:

ErrorCauseFix
❌ (5) Could not resolve proxyTypo in hostCheck host name
❌ (7) Failed to connectWrong portCheck port
❌ (56) response 407Wrong credentialsFix login
❌ (35) SSL connect errorhttps:// for plain proxyUse http://
❌ (97) proxy handshake errorWrong SOCKS versionMatch scheme
❌ (28) timeoutSlow proxy--connect-timeout 10 --max-time 30

💡 Most proxy problems come down to a wrong scheme or an unencoded password, so run -v first.

Rotating IPs with curl in scripts

Loop through a proxy list in bash, or use your provider's rotating port that gives each connection a new IP.

while read -r p; do curl -s -x "$p" https://api.ipify.org; sleep 2; done < proxies.txt

Running curl with proxy rotation suits load spreading and regional QA.

  • 💡 Pause between requests, follow robots.txt and site ToS, collect only public data.

Which proxy type to use with curl

SOCKS5 suits non-HTTP traffic, residential suits geo tests, static IPs suit long sessions.

Typical tasks and the proxy type for each:

TaskProxy typeWhy
API tests by countryResidentialReal ISP IPs
Long sessionsStatic ISPSame IP for hours
Mobile site versionMobileCarrier IPs
Non-HTTP protocolsSOCKS5Any TCP traffic

Ready to test? Try insocks SOCKS5 proxies or residential proxies: start with a demo, then sign up for full access.

Key takeaways

  • ✅ -x sets the proxy; the scheme picks the protocol.
  • ✅ The h variant of SOCKS5 keeps DNS and IP in one location.
  • ✅ Keep passwords out of shell history.
  • ✅ Verify the exit IP and -v output first.

Frequently asked questions

How do I use a proxy with curl?

Add -x and the proxy URL to the command; the scheme sets the protocol.

What is the difference between socks5 and socks5h in curl?

With socks5, your machine resolves hostnames; with the h suffix, the proxy does.

How do I pass a proxy username and password to curl?

Put them in the URL as USER:PASS@host or pass them with -U.

How do I make curl ignore the proxy?

Use --noproxy "*" or -x "" for one command.

Does curl use the http_proxy environment variable?

Yes, in lowercase and only for HTTP URLs.

Why does curl return error 407?

The proxy rejected your credentials: check the login, password and special characters.

2026-12-01