cURL SSL Proxy Examples
Complete guide to configuring static outbound SSL proxy connections using cURL. Learn how to use command-line and shell script proxy configurations with SSL verification, authentication, and advanced options.
What is a cURL SSL Proxy?
cURL SSL proxy is a command-line tool for making HTTP requests through a secure proxy server. It's essential for scripting, automation, testing, and debugging HTTP connections through proxy servers.
Use Case: Perfect for shell scripting, CI/CD pipelines, and automated testing where you need reliable proxy connections with SSL support.
Basic SSL Proxy Configuration
Simple GET Request
curl -x "http://username:password@proxy.outboundgateway.com:443" \
-k \
-L \
--proxy-user "username:password" \
--connect-timeout 15 \
--max-time 30 \
--user-agent "MyApp/1.0" \
"https://httpbin.org/ip"
Expected Response:
{
"origin": "203.0.113.1"
}
POST Request with JSON Data
curl -x "http://username:password@proxy.outboundgateway.com:443" \
-k \
-L \
--proxy-user "username:password" \
--connect-timeout 15 \
--max-time 30 \
-X POST \
-H "Content-Type: application/json" \
-d '{"name": "test", "value": "data"}' \
"https://httpbin.org/post"
Advanced SSL Configuration
SSL Certificate Verification
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--cacert /path/to/ca-bundle.crt \
--cert /path/to/client.crt \
--key /path/to/client.key \
--ssl-reqd \
--tlsv1.2 \
--tls-max 1.3 \
--connect-timeout 15 \
--max-time 30 \
"https://httpbin.org/ip"
Different SSL Protocol Versions
# TLS 1.2 only
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--tlsv1.2 \
--tls-max 1.2 \
--cipher "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256" \
"https://httpbin.org/ip"
# TLS 1.3 only
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--tlsv1.3 \
--tls-max 1.3 \
--cipher "TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256" \
"https://httpbin.org/ip"
Proxy Authentication Methods
# Basic Authentication
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--proxy-basic \
"https://httpbin.org/ip"
# Digest Authentication
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--proxy-digest \
"https://httpbin.org"
# NTLM Authentication
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--proxy-ntlm \
"https://httpbin.org/ip"
# Negotiate Authentication
curl -x "http://username:password@proxy.outboundgateway.com:443" \
--proxy-negotiate \
"https://httpbin.org/ip"
Shell Script Examples
Simple Proxy Script
#!/bin/bash
# Proxy configuration
PROXY_HOST="proxy.outboundgateway.com"
PROXY_PORT="443"
PROXY_USER="your_username"
PROXY_PASS="your_password"
# Target URL
TARGET_URL="https://httpbin.org/ip"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to make proxy request
make_proxy_request() {
local url="$1"
local method="${2:-GET}"
local data="$3"
echo -e "${YELLOW}Making $method request to $url${NC}"
curl_cmd="curl -x \"http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT\""
curl_cmd+=" -k -L --connect-timeout 15 --max-time 30"
if [[ "$method" == "POST" ]]; then
curl_cmd+=" -X POST -H \"Content-Type: application/json\""
[[ -n "$data" ]] && curl_cmd+=" -d '$data'"
fi
curl_cmd+=" \"$url\""
# Execute the command
eval "$curl_cmd"
return $?
}
# Main script
echo "=== SSL Proxy Test Script ==="
echo
# Test GET request
echo "Testing GET request..."
make_proxy_request "$TARGET_URL" "GET"
echo
# Test POST request
echo "Testing POST request..."
POST_DATA='{"test": "data", "timestamp": "'$(date -Iseconds)'"}'
make_proxy_request "$TARGET_URL/post" "POST" "$POST_DATA"
echo
echo "=== Script completed ==="
Advanced Script with Error Handling
#!/bin/bash
# Configuration
PROXY_HOST="proxy.outboundgateway.com"
PROXY_PORT="443"
PROXY_USER="your_username"
PROXY_PASS="your_password"
LOG_FILE="/tmp/proxy_test.log"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Logging function
log() {
local level="$1"
shift
local message="$*"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
case "$level" in
"INFO") color="$BLUE" ;;
"WARN") color="$YELLOW" ;;
"ERROR") color="$RED" ;;
"SUCCESS") color="$GREEN" ;;
*) color="$NC" ;;
esac
echo -e "[$timestamp] ${color}[$level]${NC} $message" | tee -a "$LOG_FILE"
}
# Error handling function
handle_error() {
local exit_code=$?
local line_number=$1
local command_name=$2
local error_message=$3
log "ERROR" "Failed at line $line_number: $command_name"
log "ERROR" "Error: $error_message"
log "ERROR" "Exit code: $exit_code"
exit $exit_code
}
# Set error trap
trap 'handle_error $LINENO "$BASH_COMMAND" "$BASH_COMMAND"' ERR
# Make proxy request function
make_request() {
local url="$1"
local method="${2:-GET}"
local headers="$3"
local data="$4"
local output_file="$5"
log "INFO" "Making $method request to $url"
# Build curl command
local curl_cmd="curl -x \"http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT\""
curl_cmd+=" -k -L -s -S --connect-timeout 15 --max-time 30"
curl_cmd+=" --write-out \"%{http_code}\""
# Add method
[[ "$method" != "GET" ]] && curl_cmd+=" -X $method"
# Add headers
if [[ -n "$headers" ]]; then
for header in "$headers"; do
curl_cmd+=" -H \"$header\""
done
fi
# Add data
if [[ -n "$data" ]]; then
curl_cmd+=" -d '$data'"
fi
# Add output file
[[ -n "$output_file" ]] && curl_cmd+=" -o \"$output_file\""
curl_cmd+=" \"$url\""
# Execute and capture HTTP code
local http_code
http_code=$(eval "$curl_cmd" 2>/dev/null) || true
# Read output file if specified
local response_body=""
if [[ -n "$output_file" && -f "$output_file" ]]; then
response_body=$(cat "$output_file")
rm -f "$output_file"
fi
# Log result
if [[ "$http_code" =~ ^[0-9]+$ ]]; then
if (( http_code >= 200 && http_code < 300 )); then
log "SUCCESS" "Request successful (HTTP $http_code)"
echo "$response_body"
else
log "WARN" "Request returned HTTP $http_code"
echo "$response_body"
fi
else
log "ERROR" "Failed to get HTTP code"
return 1
fi
return 0
}
# Test function
test_endpoint() {
local name="$1"
local url="$2"
local method="${3:-GET}"
local headers="$4"
local data="$5"
log "INFO" "Testing $name endpoint"
local temp_file=$(mktemp)
local result
result=$(make_request "$url" "$method" "$headers" "$data" "$temp_file")
local exit_code=$?
if [[ $exit_code -eq 0 ]]; then
log "SUCCESS" "$name test passed"
echo "$result" | head -c 200
[[ ${#result} -gt 200 ]] && echo "..."
else
log "ERROR" "$name test failed"
fi
echo
return $exit_code
}
# Main execution
main() {
log "INFO" "Starting SSL proxy test suite"
log "INFO" "Proxy: $PROXY_HOST:$PROXY_PORT"
echo
# Test endpoints
local success_count=0
local total_tests=0
# Test 1: GET IP
((total_tests++))
if test_endpoint "GET IP" "https://httpbin.org/ip"; then
((success_count++))
fi
# Test 2: GET User Agent
((total_tests++))
if test_endpoint "GET User Agent" "https://httpbin.org/user-agent"; then
((success_count++))
fi
# Test 3: POST JSON
((total_tests++))
local post_data='{"test": "data", "timestamp": "'$(date -Iseconds)'"}'
local headers=("Content-Type: application/json")
if test_endpoint "POST JSON" "https://httpbin.org/post" "POST" "${headers[*]}" "$post_data"; then
((success_count++))
fi
# Test 4: GET Headers
((total_tests++))
if test_endpoint "GET Headers" "https://httpbin.org/headers"; then
((success_count++))
fi
# Summary
log "INFO" "Test suite completed"
log "INFO" "Passed: $success_count/$total_tests tests"
if [[ $success_count -eq $total_tests ]]; then
log "SUCCESS" "All tests passed!"
exit 0
else
log "ERROR" "Some tests failed"
exit 1
fi
}
# Run main function
main "$@"
SSL Proxy Best Practices
1. Use Environment Variables
Store credentials in environment variables instead of hardcoding them in scripts.
2. Set Proper Timeouts
Always set connection and operation timeouts to prevent hanging scripts.
3. Implement Error Handling
Check HTTP response codes and handle errors gracefully in your scripts.
4. Use SSL Verification
Only disable SSL verification for development. Always verify certificates in production.
5. Add Retry Logic
Implement retry mechanisms for transient network failures.
Common Issues and Solutions
Connection Timeouts
Solution: Increase timeout values or check network connectivity to proxy server.
SSL Certificate Verification Failed
Solution: Update CA certificates or provide custom certificate bundle. Use -k only for development.
Authentication Failures
Solution: Verify credentials and ensure proper URL encoding of special characters.
Performance Issues
Solution: Test with different timeout values and check proxy server load.
cURL Command Options Reference
| Option | Description | Example |
|---|---|---|
-x |
Set proxy server | -x http://proxy:8080 |
-k |
Insecure SSL connection (dev only) | -k |
--cacert |
CA certificate file | --cacert /path/to/ca.crt |
--connect-timeout |
Connection timeout in seconds | --connect-timeout 15 |
--max-time |
Maximum operation time in seconds | --max-time 30 |
--proxy-user |
Proxy authentication | --proxy-user user:pass |
--tlsv1.2 |
Force TLS 1.2 | --tlsv1.2 |
-v |
Verbose output | -v |
Ready to Use SSL Proxy with cURL?
Get your static SSL proxy IPs today and start making secure HTTPS connections with consistent IP addresses for your shell scripts and automation tasks.
Get Started with OutboundGatewayRelated SSL Proxy Guides
Python SSL Proxy
Complete Python examples using requests, urllib3, and aiohttp libraries.
View Python Guide →Node.js SSL Proxy
JavaScript/Node.js implementation with axios, fetch, and undici libraries.
View Node.js Guide →PHP SSL Proxy
Web-focused proxy configuration with cURL, Guzzle, and Symfony HTTP Client.
View PHP Guide →📖 Language Comparison: Looking for the best approach? Python offers excellent libraries like requests and aiohttp, while Node.js provides native async support. Java is ideal for enterprise applications, PHP works well for web applications, and cURL is perfect for shell scripting.