Use a residential proxy in Rust with reqwest: Proxy, basic_auth, and a first check

Configure Rust with reqwest with separate residential proxy host and credentials, then run one authorized request. Includes fake placeholders, checks, and troubleshooting.

This guide connects Rust with reqwest to a residential proxy and verifies one authorized request. Copy the actual protocol, host, port, username, and password from the console. The values below are deliberately fake: host proxy.example.invalid, port 10000, username USER_EXAMPLE, password PASS_EXAMPLE_NOT_REAL. Not for mainland China.

Choose rotating residential for changing exits and traffic billing, or static residential when one exit must stay fixed for the order term. A sticky session is not a static IP.

Map the console fields

Console valueExampleWhere it goes
ProtocolHTTPThe proxy URL scheme or client proxy type
Host and portproxy.example.invalid and 10000The gateway address, without credentials
Username and passwordUSER_EXAMPLE and PASS_EXAMPLE_NOT_REALSeparate authentication fields

Create reqwest::Proxy::all with the gateway address and add proxy credentials with basic_auth. Build one client and reuse it.

Minimal example

use reqwest::{Client, Proxy};
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let proxy = Proxy::all("http://proxy.example.invalid:10000")?
        .basic_auth("USER_EXAMPLE", "PASS_EXAMPLE_NOT_REAL");
    let client = Client::builder()
        .proxy(proxy)
        .timeout(Duration::from_secs(30))
        .build()?;

    let response = client.get("https://example.com/").send().await?;
    println!("{}", response.status());
    Ok(())
}

Enable the async runtime and TLS features that fit your project. This guide does not pin a crate version; confirm the API against your selected reqwest release. The target in the snippet is only a connectivity placeholder; replace it with a page you are authorized to access. For a source-IP check, use an approved endpoint that displays the request IP.

First-check sequence

ResultMeaningNext step
2xx or expected target responseThe route workedConfirm the observed exit and region
HTTP 407Proxy authentication failedRe-copy auth; do not move credentials into the host
Timeout / connection refusedRoute, protocol, port, firewall, or target issueCompare with curl testing and use a finite timeout
Unexpected region or changing exitSelection or session mismatchCheck the console parameters; use static if the order term needs one IP

For field shapes, see proxy format, HTTP / SOCKS5 setup, Docs quickstart, and 407 / timeout troubleshooting.

FAQ

What does HTTP 407 mean?

The gateway reached your client but rejected or did not receive proxy authentication. Re-copy the username and password from the console and keep them in the authentication fields.

Why does the request time out?

Check protocol, host, port, local firewall, DNS, and the authorized target. Then reduce the test to one request with a finite timeout.

Should the host include the protocol?

No. Keep the host as a hostname. Add the scheme only where the library expects a proxy URL.

Can I use SOCKS5 with this exact example?

Not necessarily. This Rust with reqwest example demonstrates an HTTP proxy. Use the protocol returned by the console and the library-specific SOCKS adapter when required.

How do I confirm the exit?

Request an authorized page that reports the source IP, compare it with your intended region or static order, and do not treat a gateway hostname as the exit.

Can a sticky session replace a static IP?

No. Sticky keeps a rotating exit for a limited window when available; a static residential order keeps its assigned exit for the order term.

May I use these placeholder credentials?

No. The example domain cannot resolve and every credential shown here is fake. Copy current values from the console.

Can I use this in mainland China?

No. ZTProxy proxy services are not supported for use in mainland China. Use only lawful, authorized targets.

Next steps

  1. Copy the current gateway and auth from the console.
  2. Run the example against one authorized target.
  3. Confirm the exit, then add retries and concurrency gradually. Compare other clients: Python, Node.js and Axios, and PHP and Guzzle.