How to Use cURL With a Proxy: The Complete Guide
Many online tasks, like browsing, downloading, or submitting data, are usually done through a browser. But did you know that all of this can be done even faster right from the command line? One of the best tools for this is cURL.
cURL offers more control and convenience when you need to handle multiple requests or large amounts of data. And when used with a proxy, its capabilities expand even further: you can bypass restrictions and remain anonymous.
In this article, we’ll explore how cURL can help you download files, send requests, and work with proxies to bypass blocks and protect your anonymity. We’ll also cover how to use cURL for web scraping and avoid common errors. Simple examples and helpful tips — everything you need awaits you below!
What is cURL and What is it Used For?
cURL (Client URL) is a command-line tool built on the libcurl library that enables sending and receiving data over the internet. It supports various protocols, such as HTTP and HTTPS for interacting with websites, FTP for file transfers, and many others.
Here are some common tasks you can accomplish with cURL:
- Download files from the internet.
- Send data to servers.
- Interact with websites and APIs.
- Use proxy servers for anonymity or bypassing restrictions.
cURL simplifies and automates repetitive tasks, making them faster and more efficient, especially when handling multiple requests or operations. It is widely used for testing, web scraping, and working with services and applications that require data exchange over the internet.
This tool is a valuable resource not only for developers and system administrators but also for anyone who needs to work with online resources via the command line or scripts.
What is a Proxy Server and What is it Used For?
A proxy server serves as a bridge between your device and the internet. When you attempt to access a website, your request is first sent to the proxy, which forwards it to the target server and returns the response to you. This allows you to interact with the internet in a slightly different way.
Here are several reasons to use proxy servers:
Which Proxies Are Best to Use?
The choice of proxy depends on your goals, tasks, and requirements for performance or anonymity. Let’s review the main types of proxies and their best use cases:
HTTP/HTTPS Proxies
HTTP proxies work exclusively with HTTP/HTTPS protocols, providing additional encryption for enhanced security.
They are widely supported by most tools and applications. Excellent for web scraping and other tasks that require automation.
SOCKS Proxies (SOCKS4 and SOCKS5)
SOCKS5 supports both TCP and UDP traffic.
Operates at a lower level than HTTP proxies, making it versatile for any protocol.
SOCKS proxies do not process headers, which increases anonymity.
For tasks requiring high anonymity or working with non-standard protocols, SOCKS5 is the best option.
Free Proxies
Free proxies are usually slow, unstable, and quickly get blocked.
They may expose your data to risks, as they do not always ensure security.
Suitable for testing or learning but not recommended for large projects.
Data Center Proxies
Use IP addresses owned by data centers rather than internet providers.
Faster and cheaper compared to residential proxies but are easier for websites to detect, as their IP addresses are often grouped and share similar characteristics.
Residential Proxies
Use real IP addresses provided by internet service providers.
Harder for websites to detect compared to data center proxies.
Ideal for websites that block regular proxies, as residential proxies make you appear as a typical user.
Mobile Proxies
IP addresses are linked to mobile network operators.
Extremely difficult to block or detect. Typically more expensive than other types of proxies.
Essential for websites requiring mobile traffic or those with advanced anti-bot systems.
Proxy Rotation
Rotating proxies helps avoid blocks and increase anonymity. This technique dynamically changes the IP addresses used for requests, reducing the risk of getting blocked due to frequent requests from a single IP.
How to set up proxy rotation with cURL:
1. Using an API to fetch proxies. Many specialized services (e.g. ProxyMesh ) provide APIs for obtaining proxies. (In this example, replace your_username and your_password with your actual login credentials provided by the ProxyMesh service):
PROXY=$(curl -s 'https://proxy.proxyMesh.com/api/proxy?username=your_username&password=your_password')
curl -x $PROXY http://example.com/ip
2. Let’s say you have a list of proxies, either from public or paid services. Here's an example with multiple proxy servers:
proxies=("http://123.45.67.89:8080" "http://98.76.54.32:8080" "http://165.178.0.1:8080")
PROXY=${proxies[$RANDOM % ${#proxies[@]}]}
curl -x $PROXY http://example.com/ip
3. If you are using curl as part of a more complex project, you can implement proxy rotation on Unix systems with third-party tools or libraries, such as proxychains. Install proxychains and configure it in /etc/proxychains.conf to enable automatic proxy rotation.
proxychains curl http://example.com
Protocols
cURL supports a wide range of protocols, enabling various types of network connections. Depending on your needs, you can select the appropriate protocol and work with it using convenient command-line commands. Here's an overview of the main protocols you can use with cURL:
HTTP (HyperText Transfer Protocol)
One of the most popular protocols for data transmission on the internet. It is used for exchanging data between a client (e.g., a browser) and a server.
Example usage: curl http://example.com
Default port: 80
HTTPS (HyperText Transfer Protocol Secure)
A secure version of HTTP that uses SSL/TLS for encrypting data and protecting against man-in-the-middle attacks.
Example usage: curl https://example.com
Default port: 443
SOCKS (Socket Secure)
A proxy protocol that enables the transmission of any type of data over the internet, including HTTP, FTP, and others, working at the socket level.
Example usage: curl --proxy socks5://proxy_host:proxy_port http://example.com
Default port: 1080
FTP (File Transfer Protocol)
A protocol for transferring files between a client and a server. It does not encrypt transmitted data.
Example usage: curl ftp://example.com/file.txt
Default port: 21
FTPS (FTP Secure)
An extension of FTP that adds encryption using SSL/TLS to secure data transmission.
Example usage: curl ftps://example.com/file.txt
Default port: 990 (for FTPS-implicit) or 21 (for FTPS-explicit)
SFTP (SSH File Transfer Protocol)
A protocol for file transfers that uses SSH to encrypt and secure data transmission.
Example usage: curl sftp://example.com/file.txt
Default port: 22
LDAP (Lightweight Directory Access Protocol)
A protocol for accessing and managing directory services, such as Active Directory or OpenLDAP.
Example usage: curl ldap://example.com
Default port: 389
POP3 (Post Office Protocol)
A protocol for retrieving emails from a mail server.
Example usage: curl pop3://pop.example.com
Default port: 110
IMAP (Internet Message Access Protocol)
A protocol for accessing and managing emails on a server.
Example usage: curl imap://imap.example.com
Default port: 143
How to Install cURL on Different Operating Systems
On Windows, macOS, and Linux, cURL is often pre-installed. You can verify this by running the following command in the terminal (use cmd or PowerShell for Windows):
curl --version
The response should display information about the cURL version, libcurl, and additionally about the supported protocols and features. If an error message appears instead of the output, for example:
Linux/macOS: command not found
Windows: 'curl' is not recognized as an internal or external command
This means that cURL is either not installed or not added to the environment variables. In this case, you need to manually install cURL for your operating system:
Windows
- Download the ready-made archive with curl.exe from the official website.
- Extract the archive and add the path to curl.exe in the environment variable PATH.
Or you can use winget:
winget install curlmacOS
To update or install, use Homebrew:
brew install curl
Linux
Ubuntu/Debian:
sudo apt update
sudo apt install curl
Fedora/RHEL/CentOS:
sudo dnf install curl # Fedora
sudo yum install curl # CentOS/RHEL
Arch Linux:
sudo pacman -S curl
cURL Commands
Let's look at commands that cover the basic use cases of curl — downloading data, making requests, and managing files:
- Retrieving Page Content (GET Request):
curl http://example.comThis command is used to get the content of a web page. curl makes a request to the specified URL and displays the result on the screen (usually the HTML code of the page). This is useful for gathering information from websites, scanning content, or testing the availability of web resources.
- POST Request (used for sending data to a server, such as when submitting forms):
curl -X POST -d "param1=value1¶m2=value2" https://example.com-X POST specifies the POST request method.
-d allows you to specify the data being sent to the server.
Example with a real website:
curl -X POST -d "name=JohnDoe&email=johndoe@example.com" https://httpbin.org/post
Additional Parameters for POST Request:
Using headers with -H:
curl -X POST -d "param1=value1" -H "Content-Type: application/x-www-form-urlencoded" https://example.com
Sending JSON data:
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://example.com
- Downloading a file from a URL (using the test website https://www.sample-videos.com):
To download and save the file in the current working directory, simply use the command with the -O (uppercase letter) option, which saves the file with the name specified in the URL.
curl https://www.sample-videos.com/img/Sample-jpg-image-50kb.jpg -OIf you need to download a file to a specific folder, additionally specify the path using the -o (lowercase letter) option:
Windows:
curl -o "C:\Users\UserName\Pictures\Sample-jpg-image-50kb.jpg" https://www.sample-videos.com/img/Sample-jpg-image-50kb.jpg
Linux/MacOS:
curl -o "/Users/UserName/Pictures/Sample-jpg-image-50kb.jpg" https://www.sample-videos.com/img/Sample-jpg-image-50kb.jpg
- Response headers check:
curl -I http://example.com
This command displays only the server's response headers, without the body of the response. The -I (or --head) flag allows you to see the meta-information about the page (such as HTTP status code, content type, date, and time of last update). This is useful for diagnostics or checking the availability of a resource.
- To authenticate using a username and password on a real website with curl, you can use the following command:
curl -u username:password https://example.com
Example with a real website:
curl -u demo:password123 https://httpbin.org/basic-auth/demo/password123
The --header (or short form -H) command in cURL is used to add HTTP headers to HTTP requests. It allows you to send additional HTTP headers that may be required by the server. For example, you can add a User-Agent:
curl --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" https://example.com
Or set up authentication using headers:
curl --header "Authorization: Bearer your_token_here" https://api.example.com
To see all available commands and their descriptions, use the following command:
curl --help allcURL and Invoke-WebRequest
Invoke-WebRequest is a PowerShell cmdlet used to perform HTTP requests, such as downloading web pages, submitting data, or downloading files. It allows working with web content directly from the command line but is not a full replacement for cURL, as it has more limited functionality and syntax.
In earlier versions of PowerShell, the curl command was an alias for Invoke-WebRequest, which often confused users who expected the standard cURL utility to work.
In later versions (Windows 10 and Windows 11), Microsoft added curl.exe — a full version of cURL similar to the one available on Linux and macOS. However, in PowerShell, the curl command may still invoke Invoke-WebRequest. To avoid this, you can use cmd instead of PowerShell, or remove the curl alias using the command Remove-Alias curl so that curl invokes the curl.exe utility directly. Alternatively, you can explicitly specify curl.exe.
curl.exe https://example.com
Basic cURL Commands for Using Proxies
Working with proxy servers in cURL provides anonymity, bypasses restrictions, and enhances security when interacting with online resources. Understanding the basic commands and parameters allows you to effectively set up proxy usage in various scenarios.
Using HTTP and HTTPS Proxies
To use an HTTP/HTTPS proxy, you can specify the proxy server using the -x or --proxy parameter:
HTTP Proxy:
curl -x http://123.456.789.012:8080 https://example.com
HTTPS Proxy:
curl -x https://123.456.789.012:8080 https://example.com
Using SOCKS Proxy
SOCKS proxies (SOCKS4 or SOCKS5) support not only HTTP and HTTPS but also other protocols.
Example for SOCKS5 proxy:
curl -x socks5://123.456.789.012:1080 https://httpbin.org/ip
Example for SOCKS4 proxy:
curl -x socks4://123.456.789.012:1080 https://httpbin.org/ip
Proxy Authentication
Sometimes proxy servers require authentication. To provide a username and password for the proxy, use the -U or --proxy-user parameter.
curl -x http://123.456.789.012:8080 -U testuser:testpassword https://httpbin.org/ipUsing Proxies with Different Protocols
cURL allows working with various types of proxies for different protocols. For example, you can use SOCKS5 for HTTP requests and HTTPS proxies for encrypted connections.
curl -x socks5://123.456.789.012:1080 -U testuser:testpassword https://httpbin.org/ip
This request will use the SOCKS5 proxy for handling HTTP requests, while the data will be transmitted through a secure HTTPS connection.
Checking IP Address via Proxy
To verify that the request is indeed passing through the proxy, you can use httpbin.org to get the current IP:
curl -x http://123.456.789.012:3128 http://httpbin.org/ip
Proxy Speed Check
To measure the proxy speed in cURL, you can use the -w (write-out) flag to get the download speed (%{speed_download}). Additionally, the -o /dev/null flag is used to ignore the output content, and the -s flag makes the command run silently.
curl -x http://123.456.789.012:3128 -o /dev/null -s -w "Download Speed: %{speed_download} bytes/sec\n" https://httpbin.org/bytes/102400
Using Proxy with User-Agent Headers
Sometimes, it's necessary to spoof the User-Agent when using a proxy:
curl -x http://123.456.789.012:3128 --A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36" http://httpbin.org/headers
Using Proxy for Specific Requests Only
You can specify which requests should go through the proxy. For example, you can use the proxy only for certain domains. The --noproxy option allows you to specify domains that will bypass the proxy:
curl --proxy http://123.456.789.012:8080 --noproxy example.com http://httpbin.org/ipHow to Use Environment Variables for Proxy Configuration
To simplify the use of proxies in curl, you can configure environment variables. This allows you to automate proxy connections without needing to specify parameters in the command line every time.
Example of using environment variables with curl:
- Linux/macOS: In Linux and macOS, proxies are configured through the terminal using the export command.
Setting the variable for an HTTP proxy:
export http_proxy=http://123.456.789.012:8080
For an HTTPS proxy:
export https_proxy=https://123.456.789.012:8080
- Windows: In Windows, environment variables can be set through the command prompt:
set http_proxy=http://123.456.789.012:8080
set https_proxy=https://123.456.789.012:8080
After that, you can use cURL, and it will automatically use the specified proxy:
curl https://example.com
To use the value of an environment variable in commands or scripts on Linux/macOS, you can use the $ sign. It allows you to refer to the variable's value. For example:
curl -x $http_proxy https://example.com
To access the value of an environment variable in Windows, the syntax with percentage signs % is used. For example:
curl -x %http_proxy% https://example.com
Security Parameters When Using Proxy
Properly configuring security settings when working with proxies will help prevent data leaks and enhance the protection of your connections on the network.
- Using the -k or --insecure flag: this option allows you to ignore SSL certificate errors, which is useful if your proxy uses a self-signed certificate:
curl -x https://123.456.789.012:8080 -k https://example.com
Certificate verification: to avoid risks when connecting via an HTTPS proxy, it's important to use the correct certificates. If you have a certificate file, use the --cacert flag:
curl -x https://123.456.789.012:8080 --cacert /path/to/certificate.crt https://example.com
- If you have multiple certificates, you can specify a directory with trusted certificates using the --capath option. This is useful when working with multiple certificates:
curl -x https://123.456.789.012:8080 --capath /path/to/certificates/ https://example.com
What Are Aliases and Why Are They Needed in cURL?
Aliases in cURL are shortened commands for frequently used parameters that make working with cURL more convenient and faster. Instead of typing long commands each time, you can create aliases for repetitive operations.
Why Use Aliases?
Simplify commands: instead of long parameters, you can use short and convenient ones.
Reduce errors: less chance of making mistakes while typing.
Save time: one alias, and all parameters are already set.
How to Set Up Aliases
Linux/macOS (Unix-like OS):
In these systems, aliases are supported directly by the shell (e.g., bash, zsh, etc.). You can add aliases to the shell configuration files (e.g., .bashrc, .zshrc, etc.) so they are available in any terminal session.
- Example for bash:
Open or create the ~/.bashrc file (or ~/.zshrc for zsh):
nano ~/.bashrc
- Add aliases:
alias curlproxy="curl -x http://123.456.789.012:8080"
After that, you can use the curlproxy command in any session.
curlproxy https://example.com
Windows:
In Windows, alias usage is not supported in the same way as in Unix-like systems. Although PowerShell allows you to create aliases using the New-Alias cmdlet, it should be noted that New-Alias does not allow assigning parameters to commands, such as a proxy server. Instead, to create aliases with parameters, you can use PowerShell functions or custom scripts.
In PowerShell:
In PowerShell, you can create a function that acts as an alias.
- Open PowerShell.
- Create a function for the alias:
function curlproxy { curl -x http://123.456.789.012:8080 $args }
If you want this function to always be available, add it to your PowerShell profile (for example, in the $PROFILE file).
In the command prompt (CMD):
In CMD, you can use a batch file (.bat) to create aliases. For example, create a file curlproxy.bat in a directory listed in the system's PATH environment variable, and write the following in this file:
curl -x http://123.456.789.012:8080 %1
Then, you can use the curlproxy command, passing parameters as arguments.
Proxy settings in the .curlrc configuration file
The .curlrc configuration file is a special file used to store default settings for the cURL utility. This file allows you to automate the process of configuring command-line parameters such as proxy servers, user agents, SSL certificates, and other options. It is particularly useful if you want to avoid specifying the same options each time you run a cURL command.
To configure a proxy in the .curlrc file, you just need to specify the appropriate parameters. For example:
proxy = "http://123.456.789.012:8080"This parameter instructs cURL to use a proxy server with the specified address and port. You can also configure proxy authentication by specifying a username and password:
proxy-user = "username:password"Once you have configured the .curlrc file, cURL will automatically apply these settings when running commands, so you won’t need to specify them manually in the command line. For example, the command:
curl http://example.comwill use the proxy specified in the .curlrc file without the need to add the -x flag or other parameters.
How to Scrape Websites Using curl and a Proxy
- Suppose you want to extract data from a specific webpage, such as http://example.com. In this case, you can use the following curl command with a proxy:
curl -x http://123.45.67.89:8080 http://example.com -o example.htmlHere:
-x http://123.45.67.89:8080 — proxy server.
http://example.com — target webpage from which you want to fetch data.
-o example.html — save the page content to the file example.html.
After executing the command, example.html will contain the HTML code of the target page.
- Let's extract the <h1> headers from the webpage https://example.com using a proxy.
Steps:
- Use the proxy server to send requests.
- Apply grep or sed to extract the data.
curl -x http://123.45.67.89:8080 https://example.com | grep -oP '<h1.*?>.*?</h1>'In PowerShell, you can use Select-String (a native cmdlet) to perform a similar task. For example:
curl.exe -x http://123.45.67.89:8080 https://example.com | Select-String -Pattern '<h1.*?>.*?</h1>' -AllMatches | ForEach-Object { $_.Matches.Value }If you have WSL (Windows Subsystem for Linux) installed, you can run the same command as on Linux:
curl -x http://123.45.67.89:8080 https://example.com | grep -oP '<h1.*?>.*?</h1>'Integration with Python and Node.js
Integrating cURL with Python and Node.js opens up many possibilities for automating requests, web scraping, and working with APIs. By using subprocess or pycurl in Python, or child_process or node-libcurl in Node.js, you can execute complex commands and extract data within your application. Let's explore how to integrate cURL with each of these languages.
In Python
To perform cURL requests in Python, we use the subprocess module.
GET request with proxy:
import subprocess
curl_command = ['curl', '-x', 'http://123.45.67.89:8080', 'https://example.com']
response = subprocess.run(curl_command, capture_output=True, text=True)
print(response.stdout)Let's do the same with pycurl:
import pycurl
from io import BytesIO
# Initialize the buffer to capture the output
buffer = BytesIO()
# Create a pycurl object
c = pycurl.Curl()
# Set the URL
c.setopt(c.URL, 'https://example.com')
# Set the proxy
c.setopt(c.PROXY, 'http://123.45.67.89:8080')
# Set the output to the buffer
c.setopt(c.WRITEDATA, buffer)
# Perform the request
c.perform()
# Get the response
response = buffer.getvalue().decode('utf-8')
# Print the response
print(response)
# Cleanup
c.close()In Node.js
To perform cURL requests in Node.js, we use the child_process module.
GET request with proxy:
const { exec } = require('child_process');
exec('curl -x http://123.45.67.89:8080 https://example.com', (error, stdout, stderr) => {
if (error) console.error(`exec error: ${error}`);
else console.log(stdout);
});Let's perform the same task using node-libcurl.
const { Curl } = require('node-libcurl');
const curl = new Curl();
curl.setOpt('URL', 'https://example.com');
curl.setOpt('PROXY', 'http://123.45.67.89:8080');
// Set up a callback to handle the response
curl.on('end', (statusCode, body, headers) => {
console.log(body);
curl.close();
});
curl.on('error', (error) => {
console.error('Error:', error); // Handle errors
});
curl.perform();In this version, node-libcurl is used to send a request through the proxy, and the response is logged when the request is complete.
Using CapMonster Cloud with cURL
Integrating CapMonster Cloud with cURL allows you to automate the CAPTCHA solving process when making HTTP requests. Here's how you can do it using cURL:
- First, register on the CapMonster Cloud service and obtain an API key.
- Create and send a CAPTCHA solving task (in our case, reCAPTCHA v2) via CapMonster Cloud — refer to the documentation:
MacOS/Linux:
curl -X POST https://api.capmonster.cloud/createTask \
-H "Content-Type: application/json" \
-d '{
"clientKey": "API_KEY",
"task": {
"type": "RecaptchaV2Task",
"websiteURL": "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
"websiteKey": "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd"
}
}'Windows (CMD):
curl -X POST https://api.capmonster.cloud/createTask ^
-H "Content-Type: application/json" ^
-d "{\"clientKey\":\"API_KEY\",\"task\":{\"type\":\"RecaptchaV2Task\",\"websiteURL\":\"https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high\",\"websiteKey\":\"6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd\"}}"- Getting the Task Result
Once the task is submitted, you will receive a task ID, which will be needed to get the response.
MacOS/Linux:
curl -X POST https://api.capmonster.cloud/getTaskResult \
-H "Content-Type: application/json" \
-d '{
"clientKey": "API_KEY",
"taskId": "task_id_received_from_createTask"
}'Windows (CMD):
curl -X POST https://api.capmonster.cloud/getTaskResult ^
-H "Content-Type: application/json" ^
-d "{\"clientKey\":\"API_KEY\",\"taskId\":\"task_id_received_from_createTask\"}"- CAPTCHA Solution
In response to the getTaskResult request, CapMonster Cloud will return the solution to the task, such as a token for reCAPTCHA, which can be used to fill out the form.
MacOS/Linux:
curl -X POST https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php \
-d "g-recaptcha-response=your_captcha_solution" \
-d "other_data=value"Windows (CMD):
curl -X POST https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php ^
-d "g-recaptcha-response=your_captcha_solution" ^
-d "other_data=value"Example of using a proxy with the createTask request
If you want to send the request through a proxy, add the -x parameter:
MacOS/Linux:
curl -x http://proxy-server:port -X POST https://api.capmonster.cloud/createTask \
-H "Content-Type: application/json" \
-d '{
"clientKey": "API_KEY",
"task": {
"type": "RecaptchaV2Task",
"websiteURL": "https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
"websiteKey": "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd"
}
}'
Windows (CMD):
curl -x http://proxy-server:port -X POST https://api.capmonster.cloud/createTask ^
-H "Content-Type: application/json" ^
-d "{\"clientKey\": \"API_KEY\", \"task\": {\"type\": \"RecaptchaV2Task\", \"websiteURL\": \"https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high\", \"websiteKey\": \"6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd\"}}"
Testing and Debugging cURL with Proxy
Debugging Output in cURL
This method is useful for checking how cURL sends a request through the proxy and whether it interprets the settings correctly.
Use the --proxy flag to specify the proxy:
curl --proxy http://123.456.7.8.9:3128 http://example.com
If the proxy requires authentication, add:
curl --proxy http://user:password@123.456.7.8.9:3128 http://example.com
Enable debugging output with the -v or --trace-ascii flag:
curl -v --proxy http://123.456.7.8.9:3128 http://example.com
This will show connection details, sent headers, and other useful information.
Example with full trace output:
curl --trace-ascii debug.log --proxy http://123.456.7.8.9:3128 http://example.com
The output will be saved in the debug.log file for detailed analysis.
Using a Local Proxy Server
This method is suitable for detailed inspection of the data sent through the proxy (including headers, request bodies, responses, etc.).
- Set up and run a local proxy server:
mitmproxy --listen-port 8080
- Configure cURL to use the local proxy:
curl --proxy http://127.0.0.1:8080 http://example.com
- Open the mitmproxy interface to analyze requests.
You will be able to see all HTTP requests and responses in real-time. This is useful for debugging to ensure that requests are sent correctly and data is transmitted through the proxy.
Additionally, connect a remote proxy through mitmproxy. If you want to use mitmproxy to monitor traffic with a remote proxy, set it up as an "upstream proxy":
mitmproxy --mode upstream:http://123.456.7.8.9:3128 --listen-port 8080
To check the availability of the proxy itself, use the --connect-timeout and --max-time flags.
curl --proxy http://123.456.7.8.9:3128 --connect-timeout 10 --max-time 15 http://example.com
Common Errors When Using cURL with Proxy
Like any tool, cURL sometimes encounters errors. Below is a list of common errors when using cURL with a proxy and their possible causes:
curl: (5) Unsupported proxy syntax. Incorrect proxy string format. Ensure the proxy format is correct.
curl: (7) Failed to connect to proxy_host port 8080: Connection refused. The proxy server is unavailable or turned off. Invalid proxy IP address or port. Check if the proxy is operational and verify the IP and port.
curl: (7) Could not resolve proxy: proxy_host. The specified proxy DNS name cannot be resolved. Ensure the hostname is correct. Try using an IP address instead of the hostname.
curl: (35) schannel: next InitializeSecurityContext failed. Issues with the SSL/TLS connection. Check HTTPS support on the proxy side. Temporarily disable certificate verification.
curl: (52) Empty reply from server. The proxy does not send a response to the request. Verify if the server is accessible through the proxy. Ensure your request is correct.
curl: (56) Proxy CONNECT aborted. The proxy terminated the connection. Incorrect proxy credentials. Verify the username and password for the proxy.
curl: (407) Proxy Authentication Required. The proxy requires authentication, but no credentials are provided. Specify the username and password in the proxy string.
curl: (28) Operation timed out. The proxy is unavailable. The server takes too long to respond. Check the availability of the proxy and server. Increase the timeout duration.
curl: (18) Transfer closed with outstanding read data remaining. The proxy unexpectedly closed the data transfer. Try another proxy. Ensure the proxy supports the requested protocol (HTTP/HTTPS).
curl: (22) The requested URL returned error: 403 Forbidden. Access to the resource through the proxy is blocked. Verify if access to the target URL is allowed through the proxy. Use another proxy.
curl: (60) SSL certificate problem. Issues verifying the server's SSL certificate. Disable SSL verification.
curl: (6) Could not resolve host: example.com. The target server's DNS name cannot be resolved through the proxy. Check the proxy's internet connection. Ensure the hostname is correct.
Conclusion
In this guide, we explored the tools cURL and proxy servers, learned how to configure proxies in cURL, and discussed the commands for effective terminal use. We reviewed common errors when working with cURL and proxies, provided solutions for each, and examined syntax differences across macOS, Linux, and Windows.
We also demonstrated how to use cURL and proxies to work with the CapMonster Cloud service for CAPTCHA solving, expanding the possibilities of automation.
Now, with this knowledge, you can confidently work with cURL and proxies in various processes, from simple requests to more complex tasks. Try applying these skills in practice and achieve new milestones in network technology!
Frequently Asked Questions
What is cURL?
How to connect a proxy in cURL?
What port is set by default in cURL?
How to use proxies with different protocols?
How to use multiple proxies with cURL simultaneously?
How to work with proxies that require authentication in cURL?
NB: Please note that the product is intended for automating tests on your own websites and sites you have legal access to.






