Use a proxy with Rust reqwest
Complete proxy requests using reqwest Proxy, account authentication, asynchronous client, and timeout.
Maintained by the ZZHTTP engineering teamUpdated September 20, 2026
Rust asynchronous services can use the caller's own locked projects reqwest And Tokyo. Agent Certification Pass Proxy Configuration, not written into the target request header.
Precondition
- Caller project installs and locks itself
reqwestWith Tokio. - The account is closed.
us.zzhttp.com:7878; Injection through controlled environmentPROXY_USERNAMEandPROXY_PASSWORD. - Set a concurrent limit and a total request timeout for the service.
Complete example
use reqwest::{Client, Proxy};
use std::{env, error::Error, time::Duration};
/// Asynchronously check the public exit IP through an authenticated proxy.
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let proxy_username = env::var("PROXY_USERNAME")?;
let proxy_password = env::var("PROXY_PASSWORD")?;
let proxy = Proxy::all("http://us.zzhttp.com:7878")?
.basic_auth(&proxy_username, &proxy_password);
let client = Client::builder()
.proxy(proxy)
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(30))
.build()?;
let body = client
.get("https://ipinfo.io/json")
.send()
.await?
.error_for_status()?
.text()
.await?;
println!("{body}");
Ok(())
}
Expected results
Proxy::allUnify HTTP and HTTPS targets to the current HTTP proxy.- Clients reuse connections and limit the connection phase and the total request time, respectively.
- Returns the proxy export detection body as a success.
Error handling
- 407 Inspection
.basic_authThe agent accounts and current interests. - Connection and request timeouts are used for the network establishment phase and the target response phase, respectively.
- Performs limited retries with shaking only on equality requests.
Safety tips
Do not use Debug Output Proxy Or client configuration. Error reports carry only the error category, task identifier and desensitized target host, and do not record the content of the proxy authentication.
Did this answer your question?
Feedback is used only to improve the public documentation and does not submit accounts or request information.