Developer Guide · 2 min read

How to Use a Proxy with curl

curl has proxy support built in: a couple of flags route any request through an HTTP or SOCKS5 endpoint. This guide gives copy-paste commands against your s4m proxy, covering authentication, HTTPS, environment variables, and how to confirm your exit IP.

Why route curl through a proxy

When curl connects directly, the destination server sees your machine's real IP address in the connection. Routing the request through a forward proxy inserts an intermediary: the destination now sees the proxy's address, while your origin stays out of the exchange. That is the whole point of proxying automated traffic — you hide the origin IP of the host actually making the request, which keeps your main server off third parties' radar.

s4m paid proxies are authenticated, datacenter SOCKS5 and HTTP endpoints, metered by the gigabyte. That model fits scripting, scraping test runs, CI pipelines, and hitting APIs from a stable address. If instead you want every app on a machine tunneled with a flat monthly rate (not metered per-GB), a WireGuard VPN connection is usually the better tool — compare metered proxy traffic against flat VPN plans on pricing. For quick throwaway tests, the free public proxy list offers third-party proxies that s4m validates continuously, but they are strictly use-at-your-own-risk and are not operated by us.

curl understands both proxy protocols natively, so no extra tooling is required — you change a single flag or a URL scheme. The practical differences:

AspectHTTP proxy (port 3128)SOCKS5 proxy (port 1080)
curl syntax-x http://...:3128-x socks5h://...:1080
HandlesHTTP and HTTPS (via CONNECT)Any TCP connection
Remote DNSYes, the proxy resolvesYes, with socks5h:// or --socks5-hostname
AuthUSER:PASSUSER:PASS

Pick HTTP when you only need web traffic; pick SOCKS5 when you want remote DNS or need to tunnel a non-HTTP protocol.

The core flags: -x, --socks5-hostname, and auth

Every example targets your s4m endpoint at proxy.s4m.online — port 3128 for HTTP, 1080 for SOCKS5 — with USER:PASS standing in for your real credentials.

bash
# 1) HTTP/HTTPS through the HTTP proxy (port 3128)
#    curl auto-issues CONNECT for https:// URLs, so TLS stays end-to-end
curl -x http://USER:[email protected]:3128 https://example.com

# 2) SOCKS5 with remote DNS (port 1080)
#    socks5h:// resolves the hostname AT the proxy (avoids local DNS leaks)
curl -x socks5h://USER:[email protected]:1080 https://example.com

# 3) Same SOCKS5 call using dedicated flags instead of a URL scheme
curl --socks5-hostname proxy.s4m.online:1080 \
     --proxy-user USER:PASS \
     https://example.com

# 4) Keep credentials out of the proxy URL with -U / --proxy-user
curl -x http://proxy.s4m.online:3128 -U USER:PASS https://example.com

# 5) --proxy is just the long form of -x
curl --proxy http://USER:[email protected]:3128 https://example.com

Set it once with proxy environment variables

Instead of adding -x to every command, export the proxy once and let curl reuse it for the whole shell session.

bash
# curl reads http_proxy in LOWERCASE only (a historical CGI safeguard);
# HTTPS_PROXY, ALL_PROXY and NO_PROXY work in either case.
export http_proxy="http://USER:[email protected]:3128"
export HTTPS_PROXY="http://USER:[email protected]:3128"

# No -x needed now:
curl https://example.com

# Prefer a SOCKS5 endpoint for everything instead:
export ALL_PROXY="socks5h://USER:[email protected]:1080"

# Let some hosts bypass the proxy entirely:
export NO_PROXY="localhost,127.0.0.1,.internal.example"

# Confirm the exit IP, then clean up:
curl https://api.ipify.org; echo
unset http_proxy HTTPS_PROXY ALL_PROXY NO_PROXY

Verify the exit IP and common gotchas

The fastest way to confirm traffic really leaves through the proxy is to ask an echo service which IP it sees. Run the same request with and without -x and compare the results.

Without the proxy you get your machine's own address; with it, you should get the s4m exit address. If the two are identical, the proxy is not being applied — recheck the scheme, the port, and whether your credentials need URL-encoding.

  • Credentials with symbols: percent-encode characters like @ or : inside USER or PASS, or avoid the issue entirely by passing them with --proxy-user.
  • SOCKS DNS leaks: use socks5h:// or --socks5-hostname so lookups happen at the proxy rather than on your local resolver.
  • 407 Proxy Authentication Required: the USER:PASS pair is missing or wrong for that endpoint.
  • Datacenter reality: s4m proxies are datacenter IPs, so a site that specifically blocks datacenter ranges will still recognize them as such.
Share this page
FAQ

Questions, answered

Should I use socks5:// or socks5h:// with curl?

Prefer socks5h:// (or the --socks5-hostname flag). It resolves the target hostname at the proxy, so your local DNS server never sees the lookup. Plain socks5:// resolves locally first, which can reveal the destination and use your own resolver.

Does HTTPS still work through an HTTP proxy?

Yes, and no extra flags are needed. For an https:// URL curl sends an HTTP CONNECT to the proxy and tunnels TLS end-to-end, so the proxy relays only the encrypted stream (it sees the hostname via SNI, not the page contents).

Are s4m proxies residential?

No. s4m paid proxies are authenticated datacenter SOCKS5 and HTTP endpoints. They are stable and metered per gigabyte, but datacenter ranges are identifiable as datacenter IPs, so they will not pass as a home connection.

Why is my HTTP_PROXY variable being ignored?

curl reads the http_proxy variable in lowercase only, a long-standing safeguard against CGI header injection. HTTPS_PROXY, ALL_PROXY and NO_PROXY are read in either case. Use lowercase http_proxy, or just pass -x on the command line.

Can I always exit from the same IP?

Yes, with the dedicated personal IP add-on. It is a static address that is yours alone, bindable to your proxy (or VPN) and associated with your s4m account. See the pricing page for details.

Get proxy credentials in minutes

Create a free s4m account to get authenticated SOCKS5 and HTTP endpoints with pay-as-you-go metered traffic, plus an optional dedicated IP. Anonymous signup and crypto payment are supported, and you can test the flags above.

People found this page by searching for

Real search phrases this page answers — the linked ones open the page that covers them in depth.