Skip to content

curl Proxy Setup: -x, Authentication, SOCKS5 and Environment Variables

curl sends a request through a proxy with one option, but the scheme in the proxy address, the way you pass the password and the environment variables all change the result. This guide covers each with a short command and shows how to confirm the proxy was used.

The -x option and the proxy address

The curl manual describes -x, or --proxy, as taking a proxy string in the form [protocol://]host[:port]. With no protocol, or with http://, curl treats it as an HTTP proxy. If you leave out the port, the manual says curl assumes 1080, so always write the port your provider gives you.

The -x option and the proxy address: example

curl -x http://proxy-host:port https://ipinfo.io/json

Replace proxy-host and port with the values from your proxy list.

The -x option and the proxy address, continued

For an https:// target through an HTTP proxy, the Everything curl book explains that curl asks the proxy for a CONNECT tunnel and then encrypts the traffic inside it, so the proxy cannot read or change the content. Adding -v shows this: you will see curl connect to the proxy, not to the website.

Username and password

Use -U, or --proxy-user, with user:password, or put the credentials in the proxy address. The curl manual says user and password in the proxy string are URL-decoded by curl, so a character such as @ is written %40 and a colon %3a. This matters because a password with @ or : breaks the address if you do not encode it.

Username and password: example

curl -x http://USERNAME:PASSWORD@proxy-host:port https://ipinfo.io/json
curl -U USERNAME:PASSWORD -x http://proxy-host:port https://ipinfo.io/json

Percent-encode special characters in the password in the first form. In the second form the credentials are given to -U and are not part of the address.

Username and password, continued

The manual also warns that credentials on the command line can be seen by other users on the same system for a moment, and says sensitive data should be read from a file instead. A config file (below) is one way to do that.

SOCKS5 and the difference between socks5 and socks5h

The manual lists socks4://, socks4a://, socks5:// and socks5h:// as the prefixes for SOCKS proxies. The Everything curl book explains the difference: with socks5:// curl resolves the website name itself, and with socks5h:// the hostname is sent to the proxy, so no name lookup happens on your computer. Use socks5h:// when you want the proxy to do the lookup.

SOCKS5 and the difference between socks5 and socks5h: example

curl -x socks5h://USERNAME:PASSWORD@proxy-host:port https://ipinfo.io/json

Use socks5:// instead if you want curl to resolve the name locally.

SOCKS5 and the difference between socks5 and socks5h, continued

If you only need to confirm which protocol your plan supports, the SOCKS5 proxies page lists it, and the proxy address, port and login guide explains the four values you need.

Environment variables and --noproxy

curl also reads environment variables. The manual says they can be written in lower or upper case, that the lower-case version has precedence, and that http_proxy is the exception: it is accepted only in lower case. The Everything curl book explains why: a web server running a CGI script sets HTTP_PROXY from an incoming request header, so curl ignores the upper-case name. The variables are http_proxy, HTTPS_PROXY, ALL_PROXY, which applies when no protocol-specific variable is set, and NO_PROXY.

Environment variables and --noproxy: example

export http_proxy="http://USERNAME:PASSWORD@proxy-host:port"
export HTTPS_PROXY="http://USERNAME:PASSWORD@proxy-host:port"
export NO_PROXY="localhost,127.0.0.1"
curl https://ipinfo.io/json

The proxy value in these variables can use the same prefixes as -x, such as socks5h://.

Environment variables and --noproxy, continued

Per the manual, the --proxy option overrides these variables, and --noproxy with a comma-separated host list, or NO_PROXY, makes curl connect to those hosts directly. Setting --proxy "" overrides a proxy that is set in the environment.

A default proxy in .curlrc

The manual names ~/.curlrc as the default config file, and the Everything curl book says each line holds one option, written with or without the leading two dashes, and that a hash starts a comment. Put the proxy there if you always use it.

A default proxy in .curlrc: example

# ~/.curlrc
proxy = "http://USERNAME:PASSWORD@proxy-host:port"

Keep the file readable only by you, because it contains the password.

Check that the proxy is used

Request https://ipinfo.io/json through the proxy. The country and org fields should describe the proxy, not your own connection; how to read them is in the proxy location guide. If the response shows your own address, an option or variable did not apply: check for a NO_PROXY match, an empty --proxy "" or a typo in the variable name.

Common errors

A 407 status means the proxy did not accept the credentials. The Everything curl book says the 407 response headers tell which authentication method the proxy wants, and that you can ask for --proxy-digest, --proxy-ntlm or --proxy-negotiate, or let curl pick with --proxy-anyauth; Basic is the default. For a plain username and password, first re-copy the values and check the encoding; see the authentication required guide. Connection refused or a timeout usually points to a wrong port or scheme, covered in the connection failed guide. If the same task runs in Python, the requests proxy guide shows the equivalent settings.

How to do it with Proxy302

Any of these commands only needs the host, port, username and password of a Proxy302 proxy. Rotating residential traffic is billed per GB and the exit country is set when you generate the proxy; HTTP is on port 2222 and SOCKS5 on port 3333 of proxy.proxy302.com. A static ISP IP stays fixed for the whole lease term and does not rotate. The table shows exits in 7 countries from our latest hourly check; the probe sends its request to ChatGPT, which is only an example target. Details are on the rotating residential page and in the proxy location guide.

Measured exits: ChatGPT from 7 countries

Measured exits: ChatGPT from 7 countries
ItemCityNetwork (ISP)ASN
United StatesBaton Rouge, LouisianaVerizon BusinessAS6167
United KingdomBirkenhead, EnglandVirgin Media LimitedAS5089
GermanyHannover, Lower Saxonyhtp GmbHAS13045
JapanSaitama, SaitamaJCOM Co., Ltd.AS9824
SingaporeYishun New Town, SingaporeSingtel Fibre BroadbandAS9506
BrazilSilvianópolis, Minas Geraisintertel telecomunicacao LTDAAS268801
IndonesiaJakarta, JakartaPT Mahawira Nusantara GrupAS151576

Hourly check of the Proxy302 probe, 28 October 2026, 14:56 UTC: one request to ChatGPT per country through a dynamic residential exit, using the public Proxy302 entry. Only the first three octets of an IP are public. One sample per country, not an average; later checks will differ.

How to do it with Proxy302: steps

  1. Step 1

    Open the rotating residential page, choose the line, and keep Protocol on HTTP or choose SOCKS5, then click Review cost and generate.

  2. Step 2

    Open My assets (the console page that holds everything you bought) and copy HOST, PORT, USERNAME and PASSWORD. The Connect page shows a ready example with your own endpoint.

  3. Step 3

    Enter the details in the browser or tool you are setting up.

  4. Step 4

    Confirm the exit with https://ipinfo.io/json through the proxy.

  5. Step 5

    From mainland China, start the helper tool from the Connect page first and keep it open while you use the proxy.

Prices and limits

The Budget line costs US$1.50 per GB, US$1.35 per GB in a 100 GB package and US$1.20 per GB at 300 GB. There is no free trial, and the smallest purchase is 1 GB. Which exit locations are available changes daily.

FAQ

Why does http_proxy only work in lower case?

The curl documentation explains that the upper-case HTTP_PROXY can be created by a web server for CGI scripts from a request header, so curl accepts only the lower-case name for HTTP. Other proxy variables accept both.

Do I need -p or --proxytunnel for HTTPS websites?

No. For https:// URLs through an HTTP proxy curl already uses a CONNECT tunnel. The manual describes --proxytunnel as making curl tunnel the traffic with a CONNECT request, which matters for non-HTTP protocols such as FTP, and which the HTTPS case already uses.

How do I use a password that contains @ or a colon?

Percent-encode it in the proxy address: @ becomes %40 and a colon %3a, as the curl manual states. Or pass it with -U.

How do I send one request without the proxy?

Use --noproxy with the host name, or --proxy "" to clear a proxy set in the environment.

Reference links

8
  1. curl manual page

    Official documentation · Confirmed on:

    Read on 28 October 2026: -x/--proxy and its schemes (http, socks4, socks4a, socks5, socks5h), default port 1080, URL decoding of the user and password, -U/--proxy-user and its warning, --noproxy, --proxytunnel, the proxy environment variables, the lower-case http_proxy note and ~/.curlrc.

  2. Everything curl: HTTP proxy

    Official documentation · Confirmed on:

    Read on 28 October 2026: an HTTP proxy is assumed by default, the CONNECT method for HTTPS targets, and -v showing the connection to the proxy.

  3. Everything curl: SOCKS proxy

    Official documentation · Confirmed on:

    Read on 28 October 2026: SOCKS4, 4a, 5 and 5h, and which side resolves the hostname.

  4. Everything curl: proxy environment variables

    Official documentation · Confirmed on:

    Read on 28 October 2026: [scheme]_proxy variables, ALL_PROXY, NO_PROXY, and why http_proxy is accepted only in lower case.

  5. Everything curl: config file

    Official documentation · Confirmed on:

    Read on 28 October 2026: one option per line, long options with or without dashes, hash comments.

  6. Everything curl: proxy authentication

    Official documentation · Confirmed on:

    Read on 28 October 2026: -U user:password, Basic by default, --proxy-digest, --proxy-negotiate, --proxy-ntlm, --proxy-anyauth, and the 407 response headers.

  7. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file of the site (values checked against the console, the backend and the price table on 18-19 October 2026): products, prices in US$ (1 PTC = US$1), lease terms, protocols and ports, countries, quantity limits, no free trial.

  8. Proxy302 hourly connectivity check

    Product observation · Confirmed on:

    Public JSON of the probe at proxy302.com/live/connectivity/chatgpt.json, read 28 October 2026, 14:56 UTC: one request per exit country through a dynamic residential exit; exit city, ASN, network and response time.

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.