Proxy Documentation

Usage examples

Practical examples demonstrating how to use the proxy product with different options.
This includes sample commands and scripts using popular tools like cURL.

# ==============================================
# Proxy Test Script using Python + requests
# ==============================================
# This script sends a request through an authenticated HTTPS proxy
# Useful for testing proxy rotation, headers, location, etc.
# Dependencies: Python 3.12, "requests" package
# 💡 SETUP INSTRUCTIONS:
# 1. Create a virtual environment (recommended):
#      python3 -m venv venv
# 2. Activate the virtual environment:
#      source venv/bin/activate
# 3. Install the required package:
#      pip3 install requests
# 4. Run the script:
#      python3 your_script.py
# ==============================================


import requests  # External library to perform HTTP requests easily

# Proxy credentials and endpoint configuration
proxy_user = "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345"
proxy_pass = "PASSWORD"
proxy_host = "rs.magneticproxy.net"
proxy_port = "443"

# Construct proxy URL with basic auth
proxy_url = f"https://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}"

# Define both HTTP and HTTPS proxies
proxies = {
   "http": proxy_url,
   "https": proxy_url
}

# Try to make a GET request through the proxy
try:
   response = requests.get("https://google.com", proxies=proxies, timeout=10)

# If successful, print the response status and body
   print("Status code:", response.status_code)
   print("Body:", response.text)

except Exception as e:
   # If something goes wrong, print full traceback
   print("[ERROR] Request failed")
   import traceback
   traceback.print_exc()
curl -x https://rs.magneticproxy.net:443
    -U "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345:<proxy_user_password>"
   https://google.com:443
const https = require('https');

const proxyUser = 'customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345';
const proxyPass = '<proxy_user_password>';
const proxyHost = 'rs.magneticproxy.net';
const proxyPort = 443;

const targetHost = 'google.com';
const targetPort = 443;

const options = {
   host: proxyHost,
   port: proxyPort,
   method: 'CONNECT',
   path: `${targetHost}:${targetPort}`,
   headers: {
       'Proxy-Authorization': 'Basic ' + Buffer.from(`${proxyUser}:${proxyPass}`).toString('base64')
   }
};

const req = https.request(options);

req.on('connect', (res, socket) => {
   if (res.statusCode === 200) {
       const requestOptions = {
           hostname: targetHost,
           port: targetPort,
           path: '/',
           method: 'GET',
           socket: socket,
           agent: false
       };
        const secureReq = https.request(requestOptions, secureRes => {
           let data = '';
           secureRes.on('data', chunk => data += chunk);
           secureRes.on('end', () => {
               console.log('Status code:', secureRes.statusCode);
               console.log(data);
           });
       });
        secureReq.on('error', err => {
           console.error('HTTPS request error:', err.message);
       });
        secureReq.end();
   } else {
       console.error('CONNECT error:', res.statusCode);
   }
});
req.on('error', err => {
   console.error('Error connecting to proxy:', err.message);
});

req.end();     
<?php

$proxyUser = "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345";
$proxyPass = "<proxy_user_password>";
$proxyHost = "rs.magneticproxy.net";
$proxyPort = 1080;

$ch = curl_init("https://google.com:443");

curl_setopt($ch, CURLOPT_PROXY, $proxyHost . ":" . $proxyPort);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyUser . ":" . $proxyPass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$response = curl_exec($ch);

if (curl_errno($ch)) {
   echo "Error de cURL: " . curl_error($ch);
} else {
   $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
   echo "HTTP code: " . $httpCode . "
";
   echo $response;
}

curl_close($ch);

?>
import java.io.*;
import java.net.*;
import java.util.Base64;

public class Main {
 public static void main(String[] args) {
   String proxyUser = "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345";
   String proxyPass = "<proxy_user_password>;"
   String proxyHost = "rs.magneticproxy.net";
   int proxyPort = 1080;

   String auth = proxyUser + ":" + proxyPass;
   String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());

   Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));

   try {
     URL url = new URL("https://google.com:443");
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
     conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedAuth);

     int status = conn.getResponseCode();
     System.out.println("Status code: " + status);

     BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
     String line;
     while ((line = in.readLine()) != null) {
       System.out.println(line);
     }
     in.close();
     conn.disconnect();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
}
using System;
using System.Net;
using System.IO;

class Program
{
   static void Main()
   {
       string proxyUser = "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345";
       string proxyPass = "<proxy_user_password>";
       string proxyHost = "rs.magneticproxy.net";
       int proxyPort = 1080;

       WebProxy proxy = new WebProxy($"{proxyHost}:{proxyPort}")
       {
           Credentials = new NetworkCredential(proxyUser, proxyPass)
       };

       HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com:443");
       request.Proxy = proxy;

       try
       {
           using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
           {
               Console.WriteLine("Status code: " + (int)response.StatusCode);

               using (var reader = new StreamReader(response.GetResponseStream()))
               {
                   Console.WriteLine(reader.ReadToEnd());
               }
           }
       }
       catch (Exception ex)
       {
           Console.WriteLine("Error: " + ex.Message);
       }
   }
}
package main

import (
   "fmt"
   "io"
   "net/http"
   "net/url"
   "strconv"

)

func main() {
   proxyUser := "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345"
   proxyPass := "<proxy_user_password>"
   proxyHost := "rs.magneticproxy.net"
   proxyPort := 443

   proxyURL, err := url.Parse("https://" + proxyUser + ":" + proxyPass + "@" + proxyHost + ":" + strconv.Itoa(proxyPort))
   if err != nil {
       fmt.Println("URL parse error:", err)
       return
   }

   transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)}
   client := &http.Client{Transport: transport}

   resp, err := client.Get("https://google.com:443")
   if err != nil {
       fmt.Println("Error:", err)
       return
   }
   defer resp.Body.Close()

   fmt.Println("Status code:", resp.StatusCode)
   body, _ := io.ReadAll(resp.Body)
   fmt.Println(string(body))
}
# Requires: pip install PySocks
import socks
import smtplib
import socket

proxy_host = "rs.magneticproxy.net"
proxy_port = 9000
proxy_user = "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345"
proxy_pass = "<proxy_user_password>"

socks.set_default_proxy(
   socks.SOCKS5, proxy_host, proxy_port, True, proxy_user, proxy_pass
)
socket.socket = socks.socksocket

try:
   server = smtplib.SMTP("google.com", 443, timeout=10)
   print("Connected to SMTP server")
   server.quit()
except Exception as e:
   print("Error:", e)
curl -x socks5://rs.magneticproxy.net:9000
    -U "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345"
   https://google.com:443
// Requires: npm install socks

const { SocksClient } = require('socks');

SocksClient.createConnection({
 proxy: {
   host: 'rs.magneticproxy.net',
   port: 9000,
   type: 5,
   userId: 'customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345',
   password: '<proxy_user_password>'
 },
 command: 'connect',
 destination: {
   host: 'google.com',
   port: 443
 }
}).then(info => {
 console.log('Connected to SMTP server');

 // Optional: send HELO and receive response
 info.socket.write('HELO example.com');

 info.socket.on('data', (chunk) => {
   console.log('SMTP Response:' + chunk.toString());
   info.socket.end();
 });
}).catch(err => {
 console.error('Connection failed:', err.message);
});
<?php
// Requires: php-socks-client (https://github.com/leproxy/php-socks-client)
// Install via Composer: composer require clue/socks-react


require 'vendor/autoload.php';

use Clue/React/Socks/Client;
use React/Socket/Connector;
use React/Socket/Connection;
use React/EventLoop/Factory;
use React/Promise/PromiseInterface;

$proxyHost = 'rs.magneticproxy.net';
$proxyPort = 9000;
$proxyUser = 'customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345';
$proxyPass = '<proxy_user_password>';

$loop = Factory::create();
$proxyUri = "socks5://$proxyUser:$proxyPass@$proxyHost:$proxyPort";

$connector = new Connector($loop, [
   'tcp' => new Client($proxyUri, new Connector($loop))
]);

$connector->connect('google.com:443')->then(function (Connection $conn) {
   echo "Connected to SMTP server
"
;

   $conn->write("HELO example.com

"
);

   $conn->on('data', function ($data) {
       echo "SMTP response:
$data"
;
   });
}, function (Exception $e) {
   echo "Connection failed: " . $e->getMessage() . "
"
;
});

$loop->run();
// Requires: sockslib library (https://github.com/fengyouchao/sockslib)
// Download JAR or use via Maven/Gradle if available
// MAVEN EXAMPLE:
//  <dependency>
//    <groupId>com.github.mike10004</groupId>
//    <artifactId>fengyouchao-sockslib</artifactId>
//    <version>1.0.6</version>
//  </dependency>import java.io.InputStream;


import java.io.OutputStream;
import java.net.Socket;
import sockslib.client.Socks5;
import sockslib.client.SocksSocket;
import sockslib.common.UsernamePasswordCredentials;


public class Main {

 public static void main(String[] args) {
   String proxyHost = "rs.magneticproxy.net";
   int proxyPort = 9000;
   String proxyUser = "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345";
   String proxyPass = "<proxy_user_password>";

   String targetHost = "google.com";
   int targetPort = 443;

   try {
     // Create and configure the SOCKS5 proxy client
     Socks5 socks5 = new Socks5(proxyHost, proxyPort);
     socks5.setCredentials(new UsernamePasswordCredentials(proxyUser, proxyPass));

     // Use the connect method directly from the socks5 object
     try (Socket socket = new SocksSocket(socks5, targetHost, targetPort)) {
       System.out.println("Connected to " + targetHost + ":" + targetPort + " via SOCKS5 proxy");

       OutputStream out = socket.getOutputStream();
       InputStream in = socket.getInputStream();

       // Send basic SMTP HELO command
       String heloCommand = "HELO example.com
";
       out.write(heloCommand.getBytes());
       out.flush();

       // Read response
       byte[] buffer = new byte[1024];
       int read = in.read(buffer);
       String response = new String(buffer, 0, read);
       System.out.println("Server response:
" + response);
     }
   } catch (Exception e) {
     System.err.println("Connection failed: " + e.getMessage());
   }
 }
}
// Requires: MihaZupan/HttpToSocks5Proxy (https://github.com/MihaZupan/HttpToSocks5Proxy)
// Install via NuGet: Install-Package HttpToSocks5Proxy


using System;
using MihaZupan;
using System.Net.Sockets;
class Program
{
   static void Main()
   {
       var proxy = new HttpToSocks5Proxy(
           "rs.magneticproxy.net",
           9000,
           "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345",
           "<proxy_user_password>"
       );        using (var client = proxy.CreateConnection("google.com", 443))
       {
           Console.WriteLine("Connected to SMTP server");
       }
   }
}
package main

import (
   "fmt"
   "golang.org/x/net/proxy"

)

func main() {
   auth: = & proxy.Auth {
       User: "customer-<proxy_user_name>-cc-xx-rg-zz-city-yyyy-sessid-abcde12345",
       Password: "<proxy_user_password>",
   }

   dialer,
   err: = proxy.SOCKS5("tcp", "rs.magneticproxy.net:9000", auth, proxy.Direct)
   if err != nil {
       fmt.Println("Error creating dialer:", err)
       return
   }

   conn,
   err: = dialer.Dial("tcp", "google.com:443")
   if err != nil {
       fmt.Println("Dial error:", err)
       return
   }    fmt.Println("Connected to SMTP server")
   conn.Close()
}

Python Variables

Host and port should be kept as are rs.magneticproxy.net and 80/1080, respectively. Then, you only need to update proxy_user and proxy_pass values.

Parameter

Description

Default Value

Example

proxy_user

Sets the user credentials for proxy access. Provided when a plan is purchased. In the username section custom options can be added. See Proxy Options.

None (mandatory)

customer-USERNAME

proxy_pass

Password for proxy authentication.

None (mandatory)

PASSWORD

proxy_host

Specifies the proxy server to use.

rs.magneticproxy.net

rs.magneticproxy.net

proxy_port

Proxy port.

1080 (HTTP), 80 (HTTP), 443 (HTTPS)

80

Supported Proxy Protocols

MagneticProxy supports HTTP/HTTPS/SOCKS5 protocols:

Protocol

Description

http / https

Standard HTTP/HTTPS proxying. Suitable for web traffic and tools like browsers or cURL.

socks5

SOCKS version 5 with client-side DNS resolution (the client resolves the destination IP).

socks5h

SOCKS version 5 with proxy-side DNS resolution (the proxy resolves the destination domain). The h in socks5h stands for “hostname resolution on the proxy.

Prefer socks5h if you want to hide the destination domain from the client network, if the proxy needs to resolve private or internal domains, or if you’re operating behind firewalls or VPNs where local DNS resolution may fail.

Proxy Endpoint Format

Use the following format to specify your proxy connection: <protocol>://<host>:<port>

Protocol

Host

Port(s)

Full URL

HTTP

rs.magneticproxy.net

1080/80

http://rs.magneticproxy.net:1080

HTTPS

rs.magneticproxy.net

443

https://rs.magneticproxy.net:443

SOCKS5

rs.magneticproxy.net

9000

socks5://rs.magneticproxy.net:9000

SOCKS5h

rs.magneticproxy.net

9000

socks5h://rs.magneticproxy.net:9000

Options

Detailed explanation of the available proxy options, including their purpose and functionality. They are included in the username separated by - (hyphens) between the key and the value, and also between each key-value pair.

Parameter

Description

Default Value

Example

customer

Customer Username for proxy authentication. Will be provided by email once a subscription is done.

None (mandatory)

customer-USERNAME

cc

Country code of standard ISO 3166-1 alpha-2 for proxy location. If not specified, a proxy from any location will be used. Case insensitive.

N/A

cc-us

rg

Region/state/province name for proxy location. No ISO standard, just the name. If not specified, a proxy from any location will be used. Case insensitive. The value must be in snake_case (new_york).

N/A

rg-florida

city

City name for proxy location. No ISO standard, just the name. If not specified, a proxy from any location will be used. Case insensitive. The value must be in snake_case (los_angeles).

N/A

city-miami

sessid

Session identifier for proxy. AKA Sticky session ID. Alphanumeric that must be generated by the client and always be the same for the sticky session. Do not use hyphens when creating this identifier. When sessid is present, the same proxy IP will be maintained between all requests if possible. If the IP is not available, another from the same country will be provided. If there are no more IPs from that country, an IP from any country will be provided.

N/A

sessid-abcde12345

sesstime

Session duration for proxy authentication. If not specified, a default of 30 minutes will be used. Session time value is in seconds.

1800 (30 minutes)

sesstime-60

hardcountry

Operates in tandem with sessid. When enabled, in the event that the session ID's linked proxy isn't located, and no proxy from the same country is located either, it results in failure.

false

hardcountry-true

Restricted targets

Some websites are limited or blocked on our Residential Proxy network to avoid misuse and suspicious activities. The list includes but is not limited to:

Category

Examples

Restrictions / Notes

Social Media

LinkedIn, Instagram, Facebook, X.com

Access is fully blocked; the proxy will return an error.

Government & Public

usa.gov, canada.ca, *.gov domains

Official or sensitive sites; usage is restricted.

Email Providers

Outlook, Yahoo Mail

Access is fully blocked; the proxy will return an error.

SOCKS Proxy

Port 25

Port 25 is closed by default.

If you have any question, get in touch with our customer support team at contact@magneticproxy.com or via the 24/7 live chat on our website.

Get rotating residential proxies
from real devices.

Avg. 99.95% succes rates
Avg. 0.6s response time
Automatic proxy rotation
HTTP/HTTPS/SOCKS5 protocols