Using a proxy with curl and wget: HTTP, SOCKS5, authentication, environment variables and debugging
In this article
curl is the quickest way to test a proxy: one command tells you whether it works, which IP you come out on, and where an error lies. This guide covers every way to use a proxy with curl (HTTP, SOCKS5, authentication, environment variables, excluding domains) plus debugging and what wget can do.
The basic syntax
The -x (or --proxy) option sets the proxy:
curl -x "http://USER:PASS@HOST:PORT" https://api.ipify.orgThe result is the IP the site sees. With a Singapore 4G proxy, it should be a Singapore IP. If the password has special characters, pass the login separately with -U to avoid encoding it:
curl -x "http://HOST:PORT" -U "USER:PASS" https://api.ipify.orgOr encode the characters in the proxy URL: @ becomes %40, : becomes %3A, # becomes %23.
Proxy types curl supports
| Prefix | Meaning |
|---|---|
http:// |
A plain HTTP proxy (the default if you write none) |
https:// |
Connect to the proxy over TLS (only when the provider supports it) |
socks5:// |
SOCKS5, but your machine resolves domain names |
socks5h:// |
SOCKS5, and the proxy resolves domain names (recommended) |
With SOCKS5:
curl -x "socks5h://USER:PASS@HOST:PORT" https://ipinfo.io/jsonUse socks5h so names are resolved on the proxy's side, avoiding DNS leaks through your own provider. Details in SOCKS5 vs HTTP proxies.
Environment variables
Instead of typing -x every time, set environment variables (curl and many other command-line tools read them):
export http_proxy="http://USER:PASS@HOST:PORT"
export https_proxy="$http_proxy"
export NO_PROXY="localhost,127.0.0.1,.internal.local"
curl https://api.ipify.org- curl reads
http_proxyonly in lower case (for security reasons); the other variables work in either case. ALL_PROXYapplies to every protocol without its own variable.NO_PROXYlists domains that go direct, not through the proxy. Use--noproxy "*"to skip the proxy for a single command.
On Windows
In Windows PowerShell, curl is an alias for Invoke-WebRequest. Type curl.exe, the real curl that ships with Windows 10 and 11:
curl.exe -x "http://USER:PASS@HOST:PORT" https://api.ipify.orgEnvironment variables in PowerShell:
$env:HTTPS_PROXY = "http://USER:PASS@HOST:PORT"
curl.exe https://api.ipify.orgDebugging with -v
Add -v to see every step: connecting to the proxy, authenticating, opening the tunnel, the TLS handshake with the site:
curl -v -x "http://USER:PASS@HOST:PORT" https://api.ipify.orgLines to look for:
Proxy-Authorizationsent, and a 407 response: wrong username or password.CONNECT ... 200: the proxy opened the tunnel; any later error is on the site's side.- Connection refused or a timeout before any response: wrong host or port, or your network blocks that port.
Time each leg:
curl -s -o /dev/null -x "http://USER:PASS@HOST:PORT" \
-w "proxy: %{time_connect}s tls: %{time_appconnect}s total: %{time_total}s\n" \
https://www.google.comThe full error table is in common proxy errors.
Rotate, then check with curl
With a 4G proxy, calling the rotation link is just another curl command, called directly, not through the proxy:
curl -s -m 60 "$ROTATE_URL" > /dev/null
sleep 15
curl -s -x "http://USER:PASS@HOST:PORT" https://api.ipify.orgA full wait loop (checking until the IP really changes) is in rotating proxy IPs via API.
Save the proxy in curl's config file
If you use curl through a proxy often, put the settings in ~/.curlrc (on Windows, %APPDATA%\_curlrc). curl reads it on every run:
proxy = "http://HOST:PORT"
proxy-user = "USER:PASS"From then on every curl command goes through the proxy without -x. Remember this file holds the proxy password: don't share it, and remove or edit it when you stop using the proxy. To skip the config file for one command, add -q as the very first option.
wget and proxies
wget reads the same http_proxy, https_proxy and no_proxy variables, or takes options directly:
wget -e use_proxy=yes -e https_proxy="http://HOST:PORT" \
--proxy-user=USER --proxy-password=PASS \
-qO- https://api.ipify.orgwget doesn't support SOCKS. For SOCKS5, use curl.
65Proxy proxies with curl
Our 4G proxies offer both HTTP and SOCKS5 with a username and password, so every command above works; connection details and the rotation link are under My proxies. Singapore mobile-carrier IPs, a dedicated proxy that isn't shared, priced 1 day $4, 7 days $13, 1 month $32 (200GB each), plus monthly plans with more bandwidth (500GB $40, 1TB $65). See how to buy a 4G proxy.
Frequently asked questions
Why does curl say "Unsupported proxy scheme"?
The proxy prefix is misspelt (say, sock5://) or your curl was built without that support. Check the spelling and run curl -V to see its features.
Does curl use the Windows system proxy?
No. curl doesn't read the proxy settings in Windows Settings; use -x or environment variables.
Do I need -k with a proxy?
You shouldn't. -k turns off checking the site's certificate. With an ordinary HTTP or SOCKS5 proxy, the site's certificate is still valid; if it only works with -k, something is wrong. Don't ignore it.