Using Proxies with cURL

How to use proxies with cURL for web requests, including HTTPS and SOCKS5 configuration.

Using Proxies with cURL

cURL is one of the most widely used command-line tools for making HTTP requests. It has built-in proxy support for both HTTPS and SOCKS5 proxies.

Basic Proxy Usage

Use the -x (or --proxy) flag to route requests through a proxy:

curl -x http://proxy-host:port https://api.ipify.org

With Authentication

If your proxy requires username and password:

curl -x http://username:password@proxy-host:port https://api.ipify.org

Or use the -U flag separately:

curl -x http://proxy-host:port -U username:password https://api.ipify.org

SOCKS5 Proxy

For SOCKS5 proxies, specify the protocol:

curl -x socks5://username:password@proxy-host:port https://api.ipify.org

To also resolve DNS through the SOCKS5 proxy (recommended for privacy):

curl -x socks5h://username:password@proxy-host:port https://api.ipify.org

Environment Variables

Instead of passing the proxy flag each time, set environment variables:

export http_proxy=http://username:password@proxy-host:port
export https_proxy=http://username:password@proxy-host:port

Then simply run:

curl https://api.ipify.org

cURL will automatically use the proxy from the environment variables.

Ignoring Proxy for Specific Requests

To bypass the proxy for a single request:

curl --noproxy '*' https://api.ipify.org

Common Examples

Check your proxy's external IP

curl -x http://username:password@proxy-host:port https://api.ipify.org

Make an authenticated API call through a proxy

curl -x http://username:password@proxy-host:port \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  https://api.hypeproxy.io/Utils/GetInformations

Download a file through a proxy

curl -x http://username:password@proxy-host:port \
  -o output.html \
  https://example.com

Troubleshooting

  • Connection refused: Verify the proxy host and port are correct.
  • 407 Proxy Authentication Required: Your credentials are wrong or missing. Double-check your username and password.
  • Timeout: The proxy may be down or unreachable. Try a different proxy or check your network connection.
  • SSL errors: If you get certificate errors, ensure you're using https_proxy for HTTPS destinations, not http_proxy.

Was this article helpful?