DashboardDashboardLog inTry Free for 2 Hours

How to use a curl proxy with HTTP and SOCKS5

curl sends a request through a proxy when you give it the -x option. This guide covers the HTTP and SOCKS5 forms of that option, where the login goes, how to confirm the exit IP and how to keep scheduled curl jobs steady while your mobile proxy rotates on its timer.

Every example uses HOST, PORT, USERNAME and PASSWORD as placeholders. Replace them with the values from your dashboard. If you need a proxy first, compare plans on pricing.

AtlasProxies Team · Updated · 6 min read

  • 1One Option Does the Routing-x takes the proxy URL, and its scheme (http:// or socks5h://) tells curl which protocol to speak.
  • 2Keep the Password Out of the URL-U passes the login on its own, which saves you from percent-encoding symbols in the password.
  • 3Retry Before You Trust a FailureA timer rotation can cut an open transfer, so pair --retry with requests that are safe to send twice.
On This Page
  1. Get the proxy line from your dashboard
  2. Send a request through an HTTP proxy
  3. Pass the login with -U
  4. Use SOCKS5 instead
  5. Confirm the exit IP
  6. Set the proxy once with environment variables
  7. Long-running curl jobs and the rotation timer
  8. Large downloads and the daily fair-use limit
  9. Common curl proxy errors

Get the proxy line from your dashboard

Open My Proxies and click Copy Proxy on the proxy you want to use. The copy format called "User:Pass@IP:Port" is closest to what curl expects, since you only add a scheme in front of it. A SOCKS5 proxy also offers a "socks5h://" format that is ready to paste after -x.

Check which protocol the proxy is set to, HTTP or SOCKS5. You pick it in the dashboard and can change it later. Copy the line again after a switch, since the connection details can change.

Send a request through an HTTP proxy

The shortest working command puts the whole proxy URL after -x:

curl -x http://USERNAME:PASSWORD@HOST:PORT https://api.ipify.org

curl treats a proxy written with http://, or with no scheme at all, as an HTTP proxy. For an https:// target, curl asks the proxy to open a tunnel, and the TLS session runs end to end between curl and the site.

The long form, --proxy, behaves the same and reads better in shared scripts.

OptionWhat it does
-x, --proxySets the proxy URL. The scheme picks HTTP or SOCKS5.
-U, --proxy-userPasses USERNAME:PASSWORD for the proxy, separate from the URL.
--noproxyLists hosts that should connect directly.
-m, --max-timeCaps how long one transfer may take, in seconds.
--retryRepeats a transfer after a transient error.

Pass the login with -U

A password inside the URL works until it contains a character such as @, : or /. curl URL-decodes the user and password in a proxy string, so those characters must be percent-encoded first (@ becomes %40, a colon becomes %3a). The simpler route is to leave the login out of the URL:

curl -x http://HOST:PORT -U USERNAME:PASSWORD https://api.ipify.org

curl's manual warns that a password typed on the command line can appear briefly in process listings to other users of the same machine. On a shared server, put a line such as proxy-user = USERNAME:PASSWORD in a curl config file that only your account can read, and load it with -K.

Use SOCKS5 instead

If the proxy is set to SOCKS5 in your dashboard, change only the scheme:

curl -x socks5h://USERNAME:PASSWORD@HOST:PORT https://api.ipify.org

The trailing h matters. With socks5h:// the proxy looks up the site's hostname, so the DNS query travels over the mobile connection with the rest of the request. With plain socks5:// your own machine resolves the name and only the connection goes through the proxy.

The dedicated --socks5 and --socks5-hostname options do the same, but the manual calls them superfluous now that -x accepts the scheme. Read HTTP vs SOCKS5 if you are unsure which protocol to pick, or see what the SOCKS5 option includes on SOCKS5 mobile proxies.

Confirm the exit IP

ipify answers with the caller's IP as plain text, so this command prints a single address:

curl -s -x http://HOST:PORT -U USERNAME:PASSWORD https://api.ipify.org

Run it once with the proxy and once without. The two results should differ, and the proxied one should match Current Public IP in the proxy's IP Rotation panel in your dashboard.

To watch the proxy handshake, add -v. curl prints the CONNECT request it sends to an HTTP proxy and the reply it gets. A 407 reply means the proxy did not accept the login, and 407 Proxy Authentication Required walks through the usual causes.

Set the proxy once with environment variables

For a shell session or a cron job that runs many curl commands, export the proxy instead of repeating -x. curl reads https_proxy (or HTTPS_PROXY) for https:// URLs, http_proxy in lower case only for http:// URLs, and ALL_PROXY as a fallback. A value such as socks5h://USERNAME:PASSWORD@HOST:PORT works in any of them.

An explicit -x takes priority over these variables, and NO_PROXY or --noproxy names hosts that should connect directly, such as internal endpoints.

Long-running curl jobs and the rotation timer

Your proxy moves to a new IP each time the rotation timer you chose fires, at an interval from every 5 to every 120 minutes. HOST, PORT, USERNAME and PASSWORD do not change, so the command keeps working. The exit IP is what changes, and a transfer that is mid-flight at that moment can lose its connection with an error such as a reset or an empty reply.

No command or URL triggers a rotation early, so the script has to cope with the timer.

  • Add --retry with a small count. By default curl retries timeouts and a short list of HTTP error codes. --retry-all-errors widens that to any failure, which the manual reserves for requests that can safely run twice.
  • Keep repeated requests idempotent. A GET can run twice without side effects, while a POST that creates something may not, so guard it with your own check.
  • Write downloads to a file with -o instead of piping them. Before a retry, curl clears what a failed attempt wrote to an output file, which it cannot do for a pipe.
  • Set -m so a stalled transfer ends and the retry can start, instead of hanging until the next scheduled run.
  • Log the exit IP at the start and end of each run. If the two differ, a rotation happened during the run.

Large downloads and the daily fair-use limit

On Eco and Pro, bandwidth is unlimited with 15 GB/day of fair use per proxy. A proxy that reaches 15 GB in a day stops until the limit resets the next day, so a curl loop that fetches big files can halt partway through. Ultra is truly unlimited and suits jobs that move more than that. Compare the plans on pricing, and see rotating mobile proxies for how the timer works.

Common curl proxy errors

What you seeLikely cause
A 407 reply from the proxyThe login is wrong, or a symbol in the password was not percent-encoded. Try -U instead.
Could not resolve proxyThe HOST part has a typo, or the scheme is missing its ://.
Connection refused or a connect timeoutThe PORT belongs to the other protocol, or the proxy has expired. Copy the line again from My Proxies.
The proxied IP equals your ownA NO_PROXY entry matches the target, or the command lost its -x option.

Good to Know. Send requests only within each website's terms and our Acceptable Use Policy.

Frequently Asked Questions

How do I use a proxy with curl?

Add -x followed by the proxy URL, for example "curl -x http://USERNAME:PASSWORD@HOST:PORT https://example.com". Replace the placeholders with the values from your dashboard.

What is the difference between socks5 and socks5h in curl?

With socks5h:// the proxy resolves the hostname. With socks5:// curl resolves it on your machine and sends only the address to the proxy.

My proxy password has an @ in it. What should I do?

Percent-encode it as %40 inside the URL, or pass the login separately with -U USERNAME:PASSWORD so no encoding is needed.

Can curl make the proxy switch to a new IP?

No. The IP changes only when the rotation timer you set in the dashboard fires, from every 5 to every 120 minutes. curl keeps using the same HOST and PORT across changes.

How do I make every curl command use the proxy?

Export https_proxy and http_proxy, or ALL_PROXY, in the shell or the cron environment. An explicit -x on a command still takes priority.

Your first mobile proxy is two minutes away.

Sign up, pick a country, and your login arrives in seconds.