Created
July 28, 2026 09:47
-
-
Save quantumproxies/b66bce786e42e56ab05c82a20e16c9d6 to your computer and use it in GitHub Desktop.
Rust: reqwest behind an authenticated residential proxy (inline URL vs basic_auth) — https://quantumproxies.io/residential-proxies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Rust: reqwest through an authenticated residential proxy. | |
| // | |
| // Cargo.toml: | |
| // reqwest = { version = "0.12", features = ["json", "socks"] } | |
| // tokio = { version = "1", features = ["full"] } | |
| // | |
| // Proxy: QuantumProxies — https://quantumproxies.io/residential-proxies | |
| // (rotating :9000, sticky :10000, SOCKS5 :12000 — flags in the username) | |
| // Credentials: https://app.quantumproxies.io/register | |
| use std::env; | |
| #[tokio::main] | |
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| let user = env::var("QP_USER").unwrap_or("YOUR_USERNAME".into()); | |
| let pass = env::var("QP_PASS").unwrap_or("YOUR_PASSWORD".into()); | |
| // Option A: credentials inline in the proxy URL | |
| let proxy_url = format!( | |
| "http://{user}-country-us:{pass}@residentialboson.quantumproxies.io:9000" | |
| ); | |
| // Option B (cleaner with special chars): .basic_auth() | |
| let proxy = reqwest::Proxy::all("http://residentialboson.quantumproxies.io:9000")? | |
| .basic_auth(&format!("{user}-country-us"), &pass); | |
| let _ = proxy_url; // pick one; B is used below | |
| let client = reqwest::Client::builder() | |
| .proxy(proxy) | |
| .timeout(std::time::Duration::from_secs(30)) | |
| .build()?; | |
| let ip: serde_json::Value = client | |
| .get("https://ipinfo.io/json") | |
| .send() | |
| .await? | |
| .json() | |
| .await?; | |
| println!("{ip}"); | |
| Ok(()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment