How to use curl with a SOCKS5 or HTTP proxy
curl talks to HTTP and SOCKS5 proxies with one flag, -x, which makes it the quickest way to test a proxy, its targeting, and the errors it returns. This guide covers HTTP and SOCKS5 syntax, authentication, rotating and sticky sessions, country targeting, and how to read proxy errors from curl's output.
Updated 9 November 2026
Prerequisites
- curl 7.71 or newer (for
--retry-all-errors); any recent macOS, Linux or Windows 10+ build has it. Check withcurl --version. - A proxy login from the dashboard under Logins, written as
USERandPASS.
curl is ideal for checking what a page returns in another country, debugging geo-specific behaviour, and testing your proxy setup before you write code.
Basic HTTP and SOCKS5 proxy
-x (or --proxy) takes a proxy URL whose scheme picks the protocol. gw.hyperproxy.io:8888 serves HTTP, HTTPS CONNECT and SOCKS5 on the same port, and port 1080 works the same. For HTTPS targets curl opens a CONNECT tunnel, so TLS stays end to end.
curl -x http://USER:PASS@gw.hyperproxy.io:8888 https://api.ipify.orgcurl reads http_proxy, https_proxy and ALL_PROXY. Note the lowercase http_proxy: curl ignores uppercase HTTP_PROXY for security reasons.
Authentication
Credentials can go in the URL or in -U / --proxy-user. -U keeps them out of the URL, which helps when the password contains special characters. Either way they can show up in your shell history and in process lists, so for scripts read them from environment variables, or from a config file passed with -K.
SOCKS5: socks5h vs socks5
With socks5h:// (or --socks5-hostname) curl sends the hostname to the proxy, which resolves it from the exit's side. With socks5:// curl resolves locally and sends an IP, which can leak DNS lookups and return addresses that don't fit the exit's region. Prefer socks5h. UDP isn't supported, so SOCKS5 is TCP-only.
# remote DNS (recommended): the proxy resolves the hostname
curl -x socks5h://USER-cc-de:PASS@gw.hyperproxy.io:8888 https://api.ipify.org
curl --socks5-hostname gw.hyperproxy.io:8888 -U "USER-cc-de:PASS" https://api.ipify.org
# local DNS: your machine resolves the hostname, then connects by IP
curl -x socks5://USER-cc-de:PASS@gw.hyperproxy.io:8888 https://api.ipify.orgRotating vs sticky IPs
Rotation is per connection, and each curl run opens a new one, so running curl again gives a new IP. To keep one IP, add a session id (letters and digits) to the username. It lasts 5 minutes by default, or up to 120 with ttl.
# each curl run is a new connection, so each prints a different IP
for i in 1 2 3; do
curl -s -x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 https://api.ipify.org; echo
doneCountry and city targeting
Add -key-value options to the username. curl is a handy way to check spellings before using them in code. See Targeting.
curl -x http://USER-cc-de:PASS@gw.hyperproxy.io:8888 https://api.ipify.org
curl -x http://USER-cc-us-city-new_york-strict-false:PASS@gw.hyperproxy.io:8888 https://api.ipify.org
curl -x http://USER-cont-eu-os-android:PASS@gw.hyperproxy.io:8888 https://api.ipify.org| Option | Example |
|---|---|
cc | USER-cc-jp |
city | USER-cc-us-city-new_york |
region | USER-cc-us-region-california |
asn | USER-cc-de-asn-3320 |
cont | USER-cont-eu |
strict | USER-cc-us-city-houston-strict-false |
Concurrency
For batches, use --parallel or run several curl processes. Keep parallelism modest and respect each site's rate limits.
# 8 parallel transfers; with --parallel curl may reuse connections,
# so add a session per URL if each needs its own IP
curl --parallel --parallel-max 8 -x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 \
-o "page_#1.html" "https://example.com/page/[1-50]"
# or one process per URL with xargs (always a new connection)
seq 1 50 | xargs -P 8 -I{} curl -s -o page_{}.html \
-x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 https://example.com/page/{}Error handling and retries
For HTTPS targets the gateway answers the CONNECT, and curl fails with exit code 56 and a message like CONNECT tunnel failed, response 407. -w '%{http_connect}' prints that status separately from the target's %{http_code}. With SOCKS5, curl reports a SOCKS reply code instead (exit code 97). Both are mapped in Errors.
# show the gateway's answer to CONNECT
curl -sv -x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 https://api.ipify.org 2>&1 | grep -i '^< HTTP'
# print the CONNECT status and the target status separately
curl -s -o /dev/null -w 'proxy=%{http_connect} target=%{http_code}\n' \
-x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 https://api.ipify.org
# retry transient failures (502/504 from the tunnel count as errors, hence --retry-all-errors)
curl --retry 3 --retry-all-errors --retry-delay 2 --max-time 60 \
-x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 https://api.ipify.org- 407 (SOCKS: auth failure): check the login, password, balance and option spelling. Don't retry.
- 404 (SOCKS
0x04): no exit matches; widen the targeting or addstrict-false. - 403 (SOCKS
0x02): the target is not allowed. - 400: a malformed request, for example an
https://URL sent to the proxy withoutCONNECT. - 502 / 504: retry. Without a session each retry gets a new exit.
--retry-all-errors retries everything, including 407, so use it with a small --retry count, and check credentials first.
Verify the exit IP
curl -x … https://api.ipify.org prints the IP the site sees; add ?format=json for JSON. Compare it with curl https://api.ipify.org without a proxy to confirm traffic really goes through the gateway.
Troubleshooting
- curl: (56) CONNECT tunnel failed, response 407: authentication or an invalid option. Check the username one option at a time.
- curl: (97) … SOCKS5: a SOCKS auth or connection failure; try the same username over HTTP to see the status code.
- The proxy isn't used:
NO_PROXY/no_proxymatches the host, or you set an uppercaseHTTP_PROXY. - Special characters in the password: quote the URL in single quotes, or URL-encode the password.
- Windows PowerShell:
curlmay be an alias forInvoke-WebRequest; callcurl.exe.
FAQ
What is the difference between socks5 and socks5h in curl?
socks5h lets the proxy resolve hostnames; socks5 resolves them on your machine. Use socks5h with residential proxies so DNS matches the exit.
Is SOCKS5 faster than an HTTP proxy?
Not in a way you'll usually notice. Both tunnel the same TCP connection. Use whichever your tool supports best.
Does curl send my proxy password to the website?
No. It goes only to the proxy, in the CONNECT request or the SOCKS5 handshake.
How do I do this in code?
See the Python requests, axios and Go guides, or Examples.
Try it on your own workload
Sign up with GitHub or Google, create a proxy login and send your first request in a minute.
More proxy integration guides
- Python requests — Rotating and sticky residential proxies with Python requests, including SOCKS5 and retries.
- Python httpx — Sync and async httpx through a residential proxy with the proxy= argument and SOCKS5.
- Python aiohttp — High-concurrency aiohttp requests through rotating or sticky residential IPs.
- Scrapy — Route Scrapy spiders through residential proxies with request.meta and a middleware.
- Playwright — Run Playwright through residential proxies, per browser or per context, with sticky sessions.
- Puppeteer — Launch Puppeteer behind an authenticated residential proxy with page.authenticate.
- Crawlee — Map Crawlee sessions to sticky residential IPs and target countries per request.
- Node.js axios — Send axios requests through HTTP and SOCKS5 residential proxies with proxy agents.
- Node.js fetch & undici — Use Node's built-in fetch with undici ProxyAgent or NODE_USE_ENV_PROXY.
- Go net/http — Configure Go's http.Transport for HTTP and SOCKS5 residential proxies.