Skip to content

Updated

Ruby, Rust and PowerShell Proxy:
Quick Setup Snippets

  1. Ruby takes the proxy as the last four arguments of Net::HTTP.new (address, port, user, password).
  2. Rust reqwest takes Proxy::all(url) with .basic_auth(user, password).
  3. PowerShell takes -Proxy and -ProxyCredential on Invoke-WebRequest or Invoke-RestMethod. Call https://ipinfo.io/json in each case to see the exit IP.

Check it right after buyingExample output

curl -x http://USER:PASS@HOST:PORT https://ipinfo.io/json

ip
203.0.113.24
country
US
Matches the country you picked
Day 15
203.0.113.24
Same address for the whole term
Example addresses (203.0.113.0/24), not real exits
01 / 11Where the proxy goes in each language

One page, three languages: where the proxy address and the login go in Ruby, Rust and PowerShell, and how to confirm the proxy is used.

Where the proxy goes in each language

In all three languages the proxy needs the same four values: host, port, login and password. Ruby's Net::HTTP takes them as the last four arguments of Net::HTTP.new, Rust's reqwest takes a Proxy object with basic_auth, and PowerShell's Invoke-WebRequest and Invoke-RestMethod take -Proxy and -ProxyCredential.

The snippets use the HTTP port of the proxy, because that is the protocol these three standard tools document most plainly. reqwest also supports SOCKS5 once its socks feature is switched on. Every snippet calls https://ipinfo.io/json so you can read the exit IP.

Ruby: Net::HTTP with a proxy and login

require "net/http"
require "uri"

uri = URI("https://ipinfo.io/json")
http = Net::HTTP.new(uri.host, uri.port, "HOST", 2222, "LOGIN", "PASSWORD")
http.use_ssl = true
puts http.get(uri.request_uri).body

Run it with: ruby proxy.rb. Replace HOST, LOGIN and PASSWORD with the values from My assets; 2222 is the HTTP port.

Rust: reqwest Proxy with basic_auth

use reqwest::{Client, Proxy};

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let proxy = Proxy::all("http://HOST:2222")?.basic_auth("LOGIN", "PASSWORD");
    let client = Client::builder().proxy(proxy).build()?;
    let body = client.get("https://ipinfo.io/json").send().await?.text().await?;
    println!("{body}");
    Ok(())
}

Add reqwest and tokio to Cargo.toml. Proxy::all covers both http and https targets; Proxy::http would only cover plain http targets.

PowerShell: Invoke-RestMethod with -Proxy and -ProxyCredential

$secure = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("LOGIN", $secure)
Invoke-RestMethod -Uri "https://ipinfo.io/json" -Proxy "http://HOST:2222" -ProxyCredential $cred

Works in PowerShell 7. -ProxyCredential is valid only together with -Proxy.

Side by side

Side by side
ItemWhere the proxy goesWhere the login goesProtocol used here
Ruby Net::HTTPp_addr and p_port arguments of Net::HTTP.newp_user and p_pass argumentsHTTP, port 2222
Rust reqwestProxy::all("http://HOST:PORT").basic_auth("LOGIN", "PASSWORD")HTTP, port 2222 (SOCKS5 needs the socks feature)
PowerShell-Proxy "http://HOST:PORT"-ProxyCredential with a PSCredentialHTTP, port 2222

Built from the Ruby net-http source, the reqwest Proxy documentation and the Microsoft Learn Invoke-WebRequest page, all read on 20 November 2026.

Environment variables and rotation

Net::HTTP.new reads the http_proxy environment variable when you pass no proxy arguments, because the default for p_addr is :ENV, so a stray variable can send requests through a proxy you did not intend. PowerShell 7 reads HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY when -Proxy is not given.

With a rotating gateway a new IP appears with each new connection, not each request. Whether your client reuses a connection depends on the library, so test it: call ipinfo.io several times in a loop, count the distinct IPs and decide whether you need a fresh client object or a session.

How to do it with Proxy302

Each snippet needs four values from a Proxy302 proxy: host, port, login and password. For scraping, rotating residential traffic is billed per GB (Budget line US$1.50 per GB, Premium line US$5 per GB); HTTP is on port 2222 and SOCKS5 on port 3333 of proxy.proxy302.com, and the same login works for both. Without a session, each new connection gets a new IP, and a connection you keep open keeps its IP.

When the other side needs one fixed address, a datacenter IP lease costs US$0.25 for 1 day or US$3.99 for 30 days, and you choose HTTP or SOCKS5 when you buy it. There is no free trial; the smallest purchase is 1 GB of rotating residential traffic or one IP for one day.

How to do it with Proxy302: steps

  1. Step 1

    Open the rotating residential page, choose the line, then click Review cost and generate. For a fixed IP, buy a datacenter IP on the datacenter pay-per-IP page instead.

  2. Step 2

    Open My assets and copy HOST, PORT, USERNAME and PASSWORD exactly as they are shown there.

  3. Step 3

    Paste them into the code in this guide, using the port that matches the protocol: 2222 for HTTP, 3333 for SOCKS5.

  4. Step 4

    Run the code against https://ipinfo.io/json and check that the country and org fields describe the proxy, not your own connection.

Troubleshooting

407 Proxy Authentication Required

Check Login and password copied from My assets without spaces; in Rust, basic_auth called on the Proxy; in PowerShell, a PSCredential rather than a plain string.

Fix Copy the values again and read the authentication guide.

Stop when If the same login also fails in curl, stop changing code and contact Support with the order number.

Connection refused or timeout

Check The port matches the protocol: 2222 for HTTP, 3333 for SOCKS5, and the URL starts with http:// for the HTTP port.

Fix Fix the port or scheme, then try again; the connection guide lists the other checks.

Stop when If every port times out from your network, test from another network before changing code.

The response shows your own IP

Check An environment variable or NO_PROXY entry is taking over; in Rust, Proxy::http was used for an https:// target.

Fix Print the effective settings, switch to Proxy::all, and remove stray variables.

Stop when If ipinfo still shows your IP with the proxy set in code, check that the request really uses that client object.

FAQ

How do I use a proxy with a username and password in Ruby Net::HTTP?

Pass them to Net::HTTP.new after the address and port: Net::HTTP.new(host, port, proxy_host, proxy_port, proxy_user, proxy_pass). The Net::HTTP source documents these arguments.

Does reqwest support SOCKS5 proxies?

Yes. The reqwest documentation says to enable the socks cargo feature and use a socks5:// URL, for example Proxy::http("socks5://192.168.1.1:9000"). Test your own login with the ipinfo.io call before relying on it.

How do I pass the proxy password in PowerShell?

Build a PSCredential from the login and a SecureString password and give it to -ProxyCredential. Microsoft documents that -ProxyCredential is valid only when -Proxy is also used.

Can I use these snippets with a fixed datacenter IP?

Yes. You only change the four values: use the host, port and protocol that My assets shows for that IP.

Further reading

Setup guides Proxy302 publishes on GitHub on the same topic:

Reference links

4
  1. Ruby Net::HTTP source and documentation

    Official documentation · Confirmed on:

    Read on 20 November 2026: the Net::HTTP.new signature with p_addr, p_port, p_user and p_pass, the :ENV default and the http_proxy variable.

  2. reqwest Proxy documentation

    Official documentation · Confirmed on:

    Read on 20 November 2026: Proxy::all, Proxy::http and Proxy::https, basic_auth, and the socks feature with socks5:// URLs.

  3. Microsoft Learn: Invoke-WebRequest

    Official documentation · Confirmed on:

    Read on 20 November 2026: the -Proxy and -ProxyCredential parameters, and the HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY variables read by PowerShell 7.

  4. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file of the site (values checked against the console, the backend and the price table): products, prices in US$ (1 PTC = US$1), lease terms, protocols and ports, quantity limits, no free trial.

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.