Skip to main content
Rust

This article provides an example of using a proxy to make an HTTP request with the Rust programming language.

Friedrich Kräft avatar
Written by Friedrich Kräft
Updated over a year ago

Rust Code

In this example, we use the Residential proxy below:

resi.ipv6.plainproxies.com:8080:customer:product--resi6--pass--nicepass

This proxy is split into four parts separated by colons. We first save the proxy as a string variable, then split it into four parts at each colon (:) and then add it, with authentication, to our proxy dictionary.

use reqwest;

#[tokio::main]
async fn main() {
let proxy_string = "resi.ipv6.plainproxies.com:8080:customer:product--resi6--pass--nicepass".to_string();
let split_proxy: Vec<&str> = proxy_string.split(":").collect();

match &split_proxy[..] {
[ip, port, user, pass] => {
let uri = format!("{}:{}", ip, port);
let http = reqwest::Proxy::http(&uri).unwrap().basic_auth(user, pass);
let https = reqwest::Proxy::https(&uri).unwrap().basic_auth(user, pass);

let client = reqwest::Client::builder()
.proxy(http)
.proxy(https)
.build()
.unwrap();

let res = client.get("http://ip-api.com/json").send().await.unwrap();
}

_ => panic!(),
};
}

This requires tokio as an async driver and reqwest as a http client.

reqwest = "0.11.12"

tokio = { version = "1.12.2", features = ["full"] }

Did this answer your question?