Skip to main content

How to Use Proxies

This guide shows you how to use Aluvia proxies in different programming languages. Make sure you have generated your proxy credentials first.

Python​

Basic HTTP Request with Requests Library​

import requests

# Your Aluvia proxy credentials
proxy_host = "proxy.aluvia.io"
proxy_port = "8080"
username = "your_username"
password = "your_password"

# Configure proxy settings
proxies = {
'http': f'http://{username}:{password}@{proxy_host}:{proxy_port}',
'https': f'http://{username}:{password}@{proxy_host}:{proxy_port}'
}

# Make a request through the proxy
response = requests.get('http://lumtest.com/myip.json', proxies=proxies)
print(response.json())

With Smart Routing​

import requests

# Your Aluvia proxy credentials with smart routing
proxy_host = "proxy.aluvia.io"
proxy_port = "8080"
username = "your_username-routing-smart" # Add smart routing parameter
password = "your_password"

proxies = {
'http': f'http://{username}:{password}@{proxy_host}:{proxy_port}',
'https': f'http://{username}:{password}@{proxy_host}:{proxy_port}'
}

# Requests will be intelligently routed for optimal cost and performance
response = requests.get('http://lumtest.com/myip.json', proxies=proxies)
print(response.json())

With Sticky Sessions​

import requests

# Your Aluvia proxy credentials with session
proxy_host = "proxy.aluvia.io"
proxy_port = "8080"
username = "your_username-session-abc123" # Add session parameter
password = "your_password"

proxies = {
'http': f'http://{username}:{password}@{proxy_host}:{proxy_port}',
'https': f'http://{username}:{password}@{proxy_host}:{proxy_port}'
}

# Multiple requests will use the same IP
for i in range(3):
response = requests.get('http://lumtest.com/myip.json', proxies=proxies)
print(f"Request {i+1}: {response.json()}")

Combining Smart Routing with Sticky Sessions​

import requests

# Combine smart routing with sticky sessions
proxy_host = "proxy.aluvia.io"
proxy_port = "8080"
username = "your_username-routing-smart-session-xyz789"
password = "your_password"

proxies = {
'http': f'http://{username}:{password}@{proxy_host}:{proxy_port}',
'https': f'http://{username}:{password}@{proxy_host}:{proxy_port}'
}

# Smart routing with session persistence
for i in range(3):
response = requests.get('http://lumtest.com/myip.json', proxies=proxies)
print(f"Smart routed request {i+1}: {response.json()}")

Node.js​

Basic HTTP Request with Axios​

const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');

// Your Aluvia proxy credentials
const proxyHost = 'proxy.aluvia.io';
const proxyPort = '8080';
const username = 'your_username';
const password = 'your_password';

// Create proxy agent
const proxyUrl = `http://${username}:${password}@${proxyHost}:${proxyPort}`;
const agent = new HttpsProxyAgent(proxyUrl);

// Make request through proxy
axios.get('http://lumtest.com/myip.json', {
httpsAgent: agent,
httpAgent: agent
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error.message);
});

With Fetch API​


const fetch = require('node-fetch');
const { HttpsProxyAgent } = require('https-proxy-agent');

// Your Aluvia proxy credentials
const proxyHost = 'proxy.aluvia.io';
const proxyPort = '8080';
const username = 'your_username';
const password = 'your_password';

(async () => {
const agent = new HttpsProxyAgent(`http://${username}:${password}@${proxyHost}:${proxyPort}`);
const res = await fetch('http://lumtest.com/myip.json', { agent });
const body = await res.text();

console.log(body);
// The output will show information about the IP address provided by Aluvia
})();

With Smart Routing​

const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');

// Smart routing configuration
const proxyHost = 'proxy.aluvia.io';
const proxyPort = '8080';
const username = 'your_username-routing-smart';
const password = 'your_password';

const proxyUrl = `http://${username}:${password}@${proxyHost}:${proxyPort}`;
const agent = new HttpsProxyAgent(proxyUrl);

axios.get('http://lumtest.com/myip.json', {
httpsAgent: agent,
httpAgent: agent
})
.then(response => {
console.log('Smart routed response:', response.data);
})
.catch(error => {
console.error('Error:', error.message);
});

cURL​

Basic Request​

curl -x proxy.aluvia.io:8080 -U your_username:your_password http://lumtest.com/myip.json

With Smart Routing​

curl -x proxy.aluvia.io:8080 -U your_username-routing-smart:your_password http://lumtest.com/myip.json

With Sticky Sessions​

curl -x proxy.aluvia.io:8080 -U your_username-session-xyz789:your_password http://lumtest.com/myip.json

Combining Smart Routing with Sticky Sessions​

curl -x proxy.aluvia.io:8080 -U your_username-routing-smart-session-abc123:your_password http://lumtest.com/myip.json

Basic Request​

curl -x proxy.aluvia.io:8080 -U your_username:your_password http://lumtest.com/myip.json
curl -x http://jZRBAFEN:uqcHuRbG@proxy.aluvia.io:8080

With Sticky Sessions​

curl -x proxy.aluvia.io:8080 -U your_username-session-xyz789:your_password http://lumtest.com/myip.json

PHP​

Basic Request with cURL​

<?php
// Your Aluvia proxy credentials
$proxy_host = 'proxy.aluvia.io';
$proxy_port = '8080';
$username = 'your_username';
$password = 'your_password';

// Initialize cURL
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, 'http://lumtest.com/myip.json');
curl_setopt($ch, CURLOPT_PROXY, $proxy_host . ':' . $proxy_port);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Check for errors
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
echo 'Response: ' . $response;
}

curl_close($ch);
?>

With Smart Routing​

<?php
// Smart routing configuration
$proxy_host = 'proxy.aluvia.io';
$proxy_port = '8080';
$username = 'your_username-routing-smart';
$password = 'your_password';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://httpbin.org/ip');
curl_setopt($ch, CURLOPT_PROXY, $proxy_host . ':' . $proxy_port);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($ch);

if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
echo 'Smart routed response: ' . $response;
}

curl_close($ch);
?>

Important Notes​

  • Replace your_username and your_password with your actual Aluvia credentials
  • For sticky sessions, append -session- followed by a random alphanumeric string to your username
  • All requests are billed at $3/GB for data usage
  • Use Aluvia Intelligence to optimize costs by routing compatible requests through free datacenter proxies

Need Help?​

If you encounter any issues, check our support documentation or contact our support team.