This browser does not support JavaScript

How to Use cURL with Proxy

Post Time: 2025-05-13 Update Time: 2025-05-13

cURL is a powerful command-line tool for transferring data via URLs, widely used for API interactions, web scraping, and testing. Proxies enhance cURL by adding anonymity, bypassing geo-blocks, and preventing IP bans. This guide covers installation, basic to advanced proxy configurations, and troubleshooting. We hope it can do real help for you. 

Introduction to cURL and Proxies

curl

cURL (“Client URL”) is a command-line utility built on libcurl for transferring data via URL syntax. It supports HTTP, HTTPS, FTP, SFTP, LDAP, SCP, SMTP and more.

Proxies sit between cURL and target servers to provide anonymity, geographic routing, and bypass of network blocks (e.g., Cloudflare protections). For more detailed information, you can check our beginner's guide on what is a proxy.

Installation Across Operating Systems

Windows, macOS, Linux

Ensure cURL is installed and up to date before proxy configuration.

Windows

Bundled since Windows 10.

Avoid PowerShell’s Invoke-WebRequest by invoking curl.exe.

Upgrade via [curl.se/windows] or

powershell

 

winget install curl

macOS

Pre-installed on modern releases.

For latest versions:

bash

 

brew install curl

Linux

Ubuntu/Fedora include cURL by default.

Debian/Ubuntu:

bash

 

sudo apt-get install curl

Verify with:

bash

 

curl --version

Basic Usage & Command Syntax

Core syntax for proxying requests:

bash

 

curl -x <protocol>://<proxy_host>:<proxy_port> <URL>

# or equivalently

curl --proxy <protocol>://<proxy_host>:<proxy_port> <URL>

  • Protocols: http, https, socks4, socks4a, socks5, socks5h.
  • Default ports: HTTP/SOCKS4/5 → 1080; HTTPS tunneling → 443.
  • IPv6 proxy endpoints: enclose host in brackets, e.g.

bash

 

curl -x http://[2001:db8::1]:1080 https://example.com

  • Quoting: wrap URLs or credentials containing special characters in quotes..

Proxy Authentication

Secure connections often require credentials:

1. Embedding in URL

bash

 

curl -x http://username:password@proxy_host:proxy_port https://example.com

2. Dedicated Option

bash

 

curl --proxy-user username:password --proxy http://proxy_host:proxy_port https://example.com

3. NTLM & Digest

  • NTLM: --proxy-ntlm
  • Digest: --proxy-digest

Advanced Configuration: Environment Variables & Config Files

1. Environment Variables

Set once per shell session to apply globally:

macOS/Linux

bash

 

export http_proxy="http://user:pwd@proxy_host:proxy_port"

export https_proxy="http://user:pwd@proxy_host:proxy_port"

# Exclude CIDR ranges (curl 7.86.0+):

export NO_PROXY="192.168.0.0/16,localhost"

Windows

CMD:

cmd

 

set http_proxy=http://user:pwd@proxy_host:proxy_port

set https_proxy=http://user:pwd@proxy_host:proxy_port

PowerShell:

powershell

 

$Env:http_proxy = 'http://user:pwd@proxy_host:proxy_port'

$Env:https_proxy = $Env:http_proxy

2. Per-User Configuration Files

Persist settings across sessions:

  • Unix: ~/.curlrc
  • Windows: %APPDATA%\_curlrc

Example ~/.curlrc:

text

 

proxy="http://user:pwd@proxy_host:proxy_port"

noproxy="localhost,127.0.0.1,192.168.0.0/16"

connect-timeout=10

user-agent="MyApp/1.0"

Shell Aliases

bash

 

alias proxyon='export http_proxy="http://user:pwd@proxy:port"; export https_proxy="$http_proxy"'

alias proxyoff='unset http_proxy https_proxy'

Advanced Proxy Scenarios

1. SOCKS4/5

bash

 

curl --proxy socks5://proxy_host:1080 https://example.com

2. Bypass for Specific Hosts

bash

 

curl --noproxy "internal.example.com,192.168.1.0/24" https://internal.example.com

3. SSL Certificate Issues

bash

 

curl -k https://example.com

4. Verbose Debugging

bash

 

curl -v --proxy http://proxy:port https://example.com

Troubleshooting & Best Practices

403 Forbidden: rotate IP or switch proxy type.

Connection Refused: verify host, port, firewall rules.

Timeouts: increase --connect-timeout and --max-time.

Credential Errors: double-check quoting and encoding.

Proxy Types & Protocols

HTTP: plain text, fastest but unencrypted.

HTTPS: encrypted tunnel via CONNECT.

SOCKS4 vs. SOCKS5: SOCKS5 adds IPv6, UDP, authentication.

Residential vs. Datacenter vs. Mobile: trade-offs between anonymity, speed, and detectability.

Rotating Proxies: automatic IP switching to avoid rate limits and bans.

Rotating Proxies for Dynamic Usage

For large-scale scraping, rotating proxies prevent blocks:

bash

 

# Example rotating endpoint (generic placeholder)

curl -x http://rotator_user:[email protected]:8000 https://example.com

  • Rotation strategies: per-request, per-session.
  • Health checks: ensure endpoint availability.
  • Geo-targeting: request specific locations via endpoint parameters.

Quick Reference Cheat-Sheet

Purpose Flag / Method Example Syntax
Basic HTTP proxy -x / --proxy curl -x http://host:port https://example.com
Authenticated proxy --proxy-user or embed in URL curl --proxy-user user:pwd --proxy http://host:port https://example.com
SOCKS5 proxy --proxy socks5:// curl --proxy socks5://host:1080 https://example.com
Environment variable (Linux/macOS) export http_proxy / export https_proxy export http_proxy="http://user:pwd@host:port"
Environment variable (PowerShell) $Env:http_proxy $Env:http_proxy='http://user:pwd@host:port'
Config file ~/.curlrc or %APPDATA%\_curlrc Add proxy="http://user:pwd@host:port" line
Bypass proxy --noproxy curl --noproxy "*.local" https://service.local
Ignore SSL errors -k / --insecure curl -k https://example.com
Verbose output -v curl -v --proxy http://host:port https://example.com
NTLM authentication --proxy-ntlm curl --proxy-ntlm --proxy-user user:pwd --proxy http://host:port https://example.com
Digest authentication --proxy-digest curl --proxy-digest --proxy-user user:pwd --proxy http://host:port https://example.com

FAQs

1. How can a single cURL command switch proxies?

Use the inline --proxy (-x) option to override any global settings.

2. What file permissions secure .curlrc?

Restrict to the owner: chmod 600 ~/.curlrc.

3. How to skip proxy for localhost on Linux?

Add localhost,127.0.0.1 to the NO_PROXY variable or noproxy in .curlrc.

4. Can cURL use SOCKS and HTTP simultaneously?

One proxy per request—chain multiple calls or use a local tunnel if needed.

5. What are the trade-offs between residential and datacenter proxies?

Residential: higher anonymity but slower;

Datacenter: faster but more detectable.

Use cURL with GoProxy

GoProxy’s managed proxy platform enhances these methods:

Automatic IP Rotation: built-in rotator avoids manual endpoint switching.

Global Footprint: endpoints in North America, Europe, Asia, etc.

Flexible Auth: token-based or username/password seamlessly integrated into curl commands.

Real-Time Logs & Metrics: track latency, success rates, and error codes.

SDK & API: retrieve dynamic endpoints programmatically for CI/CD environments.

Sample GoProxy Command

bash

 

curl --proxy http://gp_user:[email protected]:8000 https://example.com

Next >

How to Use CamelCamelCamel Price Tracker for Smarter Amazon Shopping
Start Your 7-Day Free Trial Now!
GoProxy Cancel anytime
GoProxy No credit card required