How To Use Proxy With cURL?

by mostafa Mar 14, 2024

Proxies are essential to avoid IP address blocking and accessing restricted web pages over a specific location. In a nutshell, proxies are servers that allow for IP address hiding by requesting the web source through another, acting as a middleware.

To add proxy to cURL, we can use the -x or --proxy options. Let's explore using these options for proxy types.

HTTP and HTTPs Proxies

The general command for setting HTTP proxy with cURL is the following:

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

The protocol indicates the HTTP protocol in the case of the HTTP proxies. It can be either htttp or https depending on the proxy type, as using the https protocol with a proxy that doesn't support it will result in errors. The proxy_host and proxy_port are configured based on the proxy itself. The proxy_host can be represented as a numeric IP address or domain name.

Here is an example of setting HTTP proxies with cURL. The actual proxy hostname and port are mocked:

# HTTP proxy
curl --proxy http://123.12.12.12:1234 http://example.com/
curl --proxy http://some_proxy_domain:1234 http://example.com/

# HTTPs proxy
curl --proxy https://123.12.12.12:1234 https://example.com/
curl --proxy https://some_proxy_domain:1234 https://example.com/

Authenticated Proxies

To proxy authentication with cURL, we only have to add the username and password as a prefix to the proxy. The same HTTP and HTTPs rules are also applied:

# HTTP proxy with authentication
curl --proxy http://username:password@123.12.12.12:1234 http://example.com/
curl --proxy http://username:password@some_proxy_domain:1234 http://example.com/

# HTTPs proxy with authentication
curl --proxy https://username:password@123.12.12.12:1234 https://example.com/
curl --proxy https://username:password@some_proxy_domain:1234 https://example.com/

SOCKS Proxies

The socks proxies operate over the SOCKS4 or the SOCKS5 protocol. Here is how to use socks proxies with cURL:

#SOCKS4
curl --proxy socks4://123.12.12.12:1234 http://example.com

#SOCKS5
curl --proxy socks5://123.12.12.12:1234 http://example.com

Related Articles

Bypass Proxy Detection with Browser Fingerprint Impersonation

Stop proxy blocks with browser fingerprint impersonation using this guide for Playwright, Selenium, curl-impersonate & Scrapfly

PROXIES
SELENIUM
PLAYWRIGHT
PUPPETEER
BLOCKING
Bypass Proxy Detection with Browser Fingerprint Impersonation

How Caching Can Cut Your Proxy Bill by 70%

Learn how intelligent caching strategies can reduce proxy costs by 40-70%. Complete guide to bandwidth optimization and proxy management.

PROXIES
How Caching Can Cut Your Proxy Bill by 70%

How to Optimize NetNut Proxies

Learn how to set up and optimize NetNut proxies for web scraping, including bandwidth reduction techniques and integration with Scrapfly Proxy Saver.

PROXIES
How to Optimize NetNut Proxies

How to Optimize Webshare Proxies

Webshare is a fast-growing proxy provider offering affordable proxy solutions for various web scraping and automation tasks. Here's how to make best of it.

PROXIES
How to Optimize Webshare Proxies

How to Optimize Oxylabs Proxies

Learn how to optimize Oxylabs proxies for efficient web scraping using Python and Scrapfly Proxy Saver. Reduce bandwidth, improve speed, and cut costs.

PROXIES
How to Optimize Oxylabs Proxies

How to Reduce Your Bright Data Bandwidth Usage

Learn how to reduce Bright Data proxy bandwidth usage using Python optimizations and Scrapfly Proxy Saver to cut data costs by up to 30%

PROXIES
How to Reduce Your Bright Data Bandwidth Usage