How to Use cURL with Proxies

Learn how to use curl with proxies in this step-by-step guide.

Dec 5, 2024
How to Use cURL with Proxies

cURL is a tool that helps you move data around online. Whether you're a developer, collecting data, or working with an API, cURL is often the best choice for command-line data transfers. Adding a proxy to cURL makes it even more powerful—giving you better privacy, security, and allowing you to access content from anywhere in the world.

In this guide, we'll show you step-by-step how to use cURL with a proxy, keeping things simple and easy to follow.

What Are Proxies?

Proxies act like middlemen for your internet connection—they send your requests through another server, which hides your real IP address. With proxies, you can access content blocked in your area, browse privately, or collect data without easily getting blocked. Static proxies, like the ones we offer at Stat Proxies, use the same IP address for all your requests, making sure your connection is stable.

Setting Up cURL

First, you need to make sure you have cURL installed on your system.

macOS: It comes pre-installed! Just open the Terminal and check the version:

curl --version


Windows: Many recent versions include it by default. Open Command Prompt to check:

curl --version
  • If it’s not there, you can download it from curl.se


Linux
: Most Linux distributions come with cURL, but if you need to install it.

sudo apt-get install curl

Using cURL with a Proxy

Now let's make cURL work with proxies. To send your requests through a proxy, use the -x option:

curl -x [protocol://][username:password@]proxyhost:port [URL]

Here’s what each part means:

  • protocol: This could be HTTP, HTTPS, or SOCKS5. If you skip it, cURL will use HTTP by default.
  • username**:password****@**: Your login information if the proxy needs it.
  • proxyhost**:port**: The IP address and port of your proxy server.

Example

Imagine you have a proxy from Stat Proxies with these details:

  • IP: 212.116.248.54
  • Port: 3128
  • Username: myuser
  • Password: mypass

To make a request through this proxy:

curl -x http://myuser:mypass@212.116.248.54:3128 https://example.com

This command will send your request through our proxy server, keeping your identity hidden.

Making Your Life Easier: Environment Variables

If you use the proxy often, you can set it as an environment variable so you don’t have to type the proxy details every time.

Linux/macOS:

export http_proxy="http://myuser:mypass@212.116.248.54:3128"
export https_proxy="http://myuser:mypass@212.116.248.54:3128"

Windows:

set http_proxy=http://myuser:mypass@212.116.248.54:3128
set https_proxy=http://myuser:mypass@212.116.248.54:3128

Now, every time you use cURL, it will automatically use the proxy.

Stat Proxies Logo