How to use curl with a proxy server

Route curl requests through HTTP, HTTPS, and SOCKS5 proxy servers for debugging and access control.

How to use curl with a proxy server

Route curl requests through HTTP, HTTPS, and SOCKS5 proxy servers for debugging and access control.

Prerequisites

  • curl installed.
  • A proxy server address and port.

Step-by-Step: Use curl with a Proxy

  1. Route a request through an HTTP proxy with the -x flag:

    curl -x http://proxy.example.com:8080 https://api.example.com/data
  2. Route through a SOCKS5 proxy:

    curl -x socks5://127.0.0.1:1080 https://api.example.com/data
  3. Authenticate with the proxy server:

    curl -x http://proxy.example.com:8080 -U proxyuser:proxypass https://api.example.com/data
  4. Set a proxy via environment variable (applies to all curl requests in the session):

    export https_proxy=http://proxy.example.com:8080
    curl https://api.example.com/data