How to use a proxy with cURL
To send a cURL request through a proxy, give the proxy with -x and its username and password with -U. The same works for HTTP and HTTPS sites; for a SOCKS5 proxy, write socks5h:// in front of the host.
curl -x http://gate.example.com:8080 -U "USERNAME:PASSWORD" https://example.comIn the examples, put your proxy's host, port, username and password in place of gate.example.com, 8080, USERNAME and PASSWORD. gate.example.com stands for the host from your dashboard. The address https://proxyron.com/api/tools/myip answers with the IP and country it sees, so every command here shows at once whether the request really left through the proxy. In Windows PowerShell, type curl.exe instead of curl: there curl is another command and does not know these options.
The commands at a glance
| Task | Option |
|---|---|
| HTTP proxy | -x http://host:port or --proxy http://host:port |
| Proxy username and password | -U "USERNAME:PASSWORD" or --proxy-user |
| SOCKS5 proxy, names resolved by the proxy | -x socks5h://host:port or --socks5-hostname host:port |
| Proxy for every command in this shell | export https_proxy=http://… |
| Skip the proxy for one command | --noproxy "*" |
| Show the exchange with the proxy | -v |
HTTP proxy
curl -x http://gate.example.com:8080 -U "USERNAME:PASSWORD" https://proxyron.com/api/tools/myipThe answer should name the proxy's exit IP, not yours. An HTTP proxy opens HTTPS sites too: cURL asks it for a tunnel (CONNECT) and the encryption runs between you and the site, so the proxy sees only the site's name. Without a scheme, -x gate.example.com:8080 also means HTTP.
The login can go into the proxy address instead: -x http://USERNAME:PASSWORD@gate.example.com:8080. Then special characters in the password must be encoded, see below.
Do not mix up -U with -u. Capital -U is the login for the proxy; small -u is the login for the site you open. With -u by mistake, the proxy gets no login and answers 407 Proxy Authentication Required.
SOCKS5 proxy
curl -x socks5h://gate.example.com:1080 -U "USERNAME:PASSWORD" https://proxyron.com/api/tools/myipWrite socks5h://, with the h. With it, the proxy looks up the site's name, as it would for a user in its country. With plain socks5://, your own computer looks it up: your DNS server sees every site you open, and a site that answers each country with its own server sends you to the one near you. socks4:// and socks4a:// do not take a password at all. Use the SOCKS5 port, here 1080: SOCKS on the HTTP port, or the other way round, ends in an error.
HTTPS proxy
With https:// in front of the proxy address, cURL encrypts the connection to the proxy itself, not only to the site. It works only when the proxy's port speaks TLS, which the provider says in its docs; most residential gateways, Proxyron's too, take plain http://, and the sites you open stay encrypted anyway. If the proxy uses its own certificate, give it with --proxy-cacert file.pem; --proxy-insecure skips the check of the proxy's certificate, and -k skips the check of the site's. Use both only for testing.
Special characters in the password
With -U, the username and password go as they are, nothing to encode: cURL splits them at the first colon. Put them in single quotes on Linux and macOS, so the shell does not touch $, ! and spaces: -U 'USERNAME:pa$$word!'. In the Windows command prompt, use double quotes.
In the proxy URL, encode the characters that have a meaning there:
| Character | In the URL |
|---|---|
@ | %40 |
: | %3A |
/ | %2F |
# | %23 |
% | %25 |
? | %3F |
The password p@ss:1 becomes p%40ss%3A1. The proxy URL generator encodes it for you and adds the country and session to the username.
Environment variables
Instead of -x in every command, set the proxy once for the shell. cURL reads these variables:
export http_proxy="http://USERNAME:PASSWORD@gate.example.com:8080"
export https_proxy="$http_proxy"
export no_proxy="127.0.0.1,.local"
curl https://proxyron.com/api/tools/myiphttp_proxyis forhttp://sites andhttps_proxyforhttps://ones; both point at the samehttp://proxy address.all_proxycovers every scheme, and is where asocks5h://address goes.- cURL reads
http_proxyonly in lower case:HTTP_PROXYin capitals is ignored, a guard against a known web server attack. The others work in either case. no_proxylists the hosts to reach directly.--noproxy "*"skips the proxy for one command, and-xoverrides the variables.- In PowerShell:
$env:https_proxy = "http://USERNAME:PASSWORD@gate.example.com:8080". In the command prompt:set https_proxy=http://…without quotes. - The variables also reach other programs, such as pip, npm, git and Python scripts. When one of them suddenly fails with 407, an old value here is a common cause.
The config file
To use the proxy in every cURL command without variables, put it into ~/.curlrc (on Windows, _curlrc in the %APPDATA% folder):
proxy = "http://gate.example.com:8080"
proxy-user = "USERNAME:PASSWORD"The password is stored as plain text, so keep the file readable only by you: chmod 600 ~/.curlrc. -q as the first option runs one command without the file.
Country and rotation
The country is set in the username: USERNAME-country-DE gives an IP in Germany. Without a session, the IP changes on every request; three requests in a row show three addresses:
for i in 1 2 3; do
curl -s -x http://gate.example.com:8080 -U "USERNAME-country-DE:PASSWORD" https://proxyron.com/api/tools/myip; echo
doneTo keep one IP for a series of requests, add a session, USERNAME-country-DE-session-ab12cd-time-10: the same IP for 10 minutes. All username options: the developer guide. When to rotate and when to hold an IP: rotating or sticky.
Read the -v output
With -v, cURL prints its side of the exchange with the proxy. For an HTTPS site through an HTTP proxy, a working run looks like this:
* Connected to gate.example.com port 8080
> CONNECT example.com:443 HTTP/1.1
> Proxy-Authorization: Basic …
< HTTP/1.1 200 Connection establishedNo Connected to line with the proxy's host means cURL went straight to the site: check the option and the variables. No Proxy-Authorization line means the login did not reach the proxy. Any answer to CONNECT other than 200 is the proxy's refusal, and its code says why.
cURL errors with a proxy
| Code | Message, cause and fix |
|---|---|
5 | Could not resolve proxy. The proxy's host name is wrong or has a typo. Copy it again, without http:// twice and without spaces. |
7 | Failed to connect to … port 8080. The proxy did not answer on that port: a wrong port, a firewall, or an office or public Wi-Fi network that blocks it. Try another network. |
56 | CONNECT tunnel failed, response 407. The proxy did not accept the login. Every cause of 407 and the fix. |
56 | CONNECT tunnel failed, response 403 or 502. The proxy accepted you but refused the site or could not reach it: a blocked site or port, no IP in the chosen country, the site down. The same causes as in the browser: ERR_TUNNEL_CONNECTION_FAILED. |
97 | The SOCKS5 handshake failed. User was rejected by the SOCKS5 server is a wrong login; Can't complete SOCKS5 connection is a site the proxy could not reach. Check that the port is the SOCKS5 one. cURL older than 7.73 shows these errors under code 7. |
35 | wrong version number. The proxy address starts with https://, but the port speaks plain HTTP. Write http://. |
28 | Operation timed out. The proxy or the site is slow. Add --connect-timeout 10 --max-time 60 and retry; with a rotating proxy, the next try goes through another IP. |
To tell a dead proxy from a wrong command, paste the proxy into the proxy checker: it says whether the proxy works, refuses the login or does not answer, and shows the exit IP.
From cURL to code
Once the command works, the same proxy goes into a script. The code generator writes it for cURL, Python requests, Node.js and Playwright with the login read from environment variables, and the format converter turns a list of host:port:user:pass lines into URLs that cURL takes.
Proxies by country
Once the proxy is set up, check that the exit IP is in the country you need. Each guide gives the username option for it.