curl with Proxy Settings

Route curl requests through HTTP, HTTPS, and SOCKS proxies. Configure proxy authentication, environment variables, and bypass rules for network access.

General

Detailed Explanation

Using Proxies with curl

Proxies act as intermediaries between your client and the destination server. curl supports HTTP, HTTPS, SOCKS4, and SOCKS5 proxies, making it versatile for various network configurations.

HTTP Proxy

curl -x http://proxy.example.com:8080 https://api.example.com/data

The -x (or --proxy) flag specifies the proxy server and port.

HTTPS Proxy

curl -x https://proxy.example.com:8443 https://api.example.com/data

SOCKS5 Proxy

curl --socks5 proxy.example.com:1080 https://api.example.com/data

With DNS resolution through the proxy:

curl --socks5-hostname proxy.example.com:1080 https://api.example.com/data

Proxy Authentication

curl -x http://proxy.example.com:8080 \
  -U proxyuser:proxypass \
  https://api.example.com/data

Or embed credentials in the proxy URL:

curl -x http://proxyuser:proxypass@proxy.example.com:8080 \
  https://api.example.com/data

Environment Variable Configuration

curl respects standard proxy environment variables:

export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,.internal.com"

curl https://api.example.com/data  # Uses proxy automatically

Bypassing Proxy for Specific Hosts

curl --noproxy "localhost,.local,.internal.com" \
  -x http://proxy.example.com:8080 \
  https://api.example.com/data

Proxy with Tunneling

For HTTPS through an HTTP proxy, curl uses the CONNECT method to create a tunnel:

curl -x http://proxy.example.com:8080 \
  --proxytunnel \
  https://api.example.com/data

Debugging Proxy Connections

curl -v -x http://proxy.example.com:8080 https://api.example.com/data

The verbose output shows the proxy CONNECT handshake and tunnel establishment. Look for lines like * CONNECT api.example.com:443 HTTP/1.1 to confirm the proxy is being used.

Common Proxy Scenarios

  • Corporate networks: Route traffic through the company proxy
  • Testing: Simulate requests from different geographic locations
  • Debugging: Use tools like mitmproxy to inspect HTTPS traffic
  • Privacy: Route requests through anonymous proxies or Tor

Use Case

A developer working behind a corporate firewall needs to route API requests through an authenticated HTTP proxy to reach external services during development and testing.

Try It — Curl to Code Converter

Open full tool