reqwest proxy setup for HTTP and SOCKS5
You configure a reqwest proxy by building a client with a Proxy::all() that points to our gateway and includes your authentication details. This works for both HTTP/HTTPS traffic on port 7070 and SOCKS5 on port 7071 when you enable the optional socks feature.
- Use Proxy::all("http://gw.rotatingproxy.cc:7070") with basic_auth for HTTP/HTTPS.
- Enable the socks feature for SOCKS5 on port 7071.
- Embed targeting like cc.us and sessions with sid in the username.
- Verify the exit IP with a simple request to ipify or ipinfo.
reqwest proxy configuration basics
The reqwest library configures a proxy through its ClientBuilder using the Proxy::all method. This method sets a proxy for all HTTP and HTTPS requests made by that client. The core setup involves providing the gateway host and port, then adding your proxy user's credentials via basic authentication. Your targeting preferences and session control are passed as part of the username string, following our specific grammar.
Where to put proxy settings in reqwest
Proxy settings are applied when you build an HTTP client, before you make any requests. You start with reqwest::Client::builder(), chain a call to .proxy() with your Proxy instance, and then call .build() to create the client. All requests made with that client will automatically route through the specified proxy. For different proxy configurations, such as targeting different countries or using separate sessions, you need to build separate client instances.
HTTP and HTTPS setup on port 7070
For HTTP and HTTPS traffic, use port 7070 on our gateway host gw.rotatingproxy.cc. Construct the proxy URL as http://gw.rotatingproxy.cc:7070 and pass it to Proxy::all. You must then set the authentication header using the basic_auth method on the Proxy object. The username includes your proxy user login and any options like network or country code.
use reqwest::{Client, Proxy};
let proxy = Proxy::all("http://gw.rotatingproxy.cc:7070")?
.basic_auth("USERNAME_net.res_cc.us", "PASSWORD");
let client = Client::builder()
.proxy(proxy)
.build()?;
let resp = client.get("https://httpbin.org/ip").send().await?;
println!("{}", resp.text().await?);
This client will send all its traffic through our rotating residential network in the United States. The Proxy::all method handles the CONNECT tunnel for HTTPS requests automatically, so you do not need separate configuration for HTTPS.
SOCKS5 setup on port 7071
Reqwest supports SOCKS5 proxies through an optional Cargo feature. To use our SOCKS5 gateway on port 7071, you must enable the socks feature in your Cargo.toml file. Check the current reqwest documentation for the exact feature name, as it can change between versions. Once the feature is enabled, you create a SOCKS5 proxy using Proxy::all with a socks5:// scheme.
// In Cargo.toml: reqwest = { version = "0.11", features = ["socks"] }
let proxy = Proxy::all("socks5://gw.rotatingproxy.cc:7071")?
.basic_auth("USERNAME_net.dc_cc.de", "PASSWORD");
let client = Client::builder()
.proxy(proxy)
.build()?;
SOCKS5 can be useful for protocols that HTTP proxies do not support, though for typical web scraping of HTTP/HTTPS sites, both ports work equally well. See our guide on which port to use for more details.
Passing targeting and session options in the username
You control the exit location and session behavior by appending options to your proxy user's login in the username field. Each option is a key.value pair joined with underscores. Country targeting uses the cc. prefix with a lowercase ISO code. For a sticky session that keeps the same IP for a period, add a sid. (session ID) and optionally a ttl. (time-to-live in minutes).
// Rotating mobile IPs from Germany, Berlin, new IP every connection
let user_rotating = "USERNAME_net.mob_cc.de_city.berlin";
// Sticky session for 30 minutes with a datacenter IP in France
let user_sticky = "USERNAME_net.dc_cc.fr_sid.a7k2m9_ttl.30";
You can target US states with st. when the country is cc.us, and cities from our published list with city.. For a full reference, visit the username options documentation.
Verifying the exit IP and location
After setting up your client, it's good practice to verify that requests are exiting through the expected proxy IP and location. You can make a simple GET request to a service that returns your IP address in plain text or JSON. The ipify.org API returns just the IP, while ipinfo.io provides location details.
let resp = client.get("https://api.ipify.org").send().await?;
println!("Exit IP: {}", resp.text().await?);
// For location details (JSON)
let resp = client.get("https://ipinfo.io/json").send().await?;
println!("Location info: {}", resp.text().await?);
Compare the returned IP country against your targeting. If you used a city target, note that IP geolocation is not always precise to the city level; read our guide on how accurate IP geolocation is.
Common errors and how to fix them
When using reqwest with our proxies, you might encounter a few specific errors. A 407 Proxy Authentication Required error indicates the gateway rejected your proxy credentials. Check that the username and password are correct, and that the username string is properly URL-encoded if you are constructing it dynamically (reqwest's basic_auth handles this). Also ensure your proxy user is not paused and has permission for the network you specified. For more on this, see proxy error 407.
Timeouts can happen if the target site responds slowly or blocks your request. Increase the timeout on your client builder with .timeout(). TLS errors sometimes arise from mismatched cipher suites; using the default Rust TLS backend (native-tls or rustls) usually works. If you see a 502 Bad Gateway from the proxy, it often indicates a temporary issue with the exit node; implement a retry with a small delay. Our retry strategies for proxy requests guide explains this in detail.
Tips for running at scale with reqwest
For large-scale scraping or data collection, you need to manage concurrency and sessions effectively. Create a pool of client instances, each with a unique session ID (sid) if you need sticky sessions for specific tasks. This approach is common for web scraping where you must maintain login state across multiple requests. Remember the account-wide concurrency limit of 1,000 connections; distribute your workload across multiple proxy users if necessary.
Monitor your traffic usage to stay within budget; the price per GB decreases automatically as your monthly volume increases. Use the reqwest client's built-in connection pooling and keep-alive to reduce overhead. For tasks like price monitoring or rank tracking, you can rotate IPs on every request by omitting the sid option, which helps avoid rate limits. Always implement polite crawling practices: respect robots.txt, add delays between requests, and rotate user agents. Read our web scraping best practices for more.
Integrating with async workflows and other crates
Reqwest is designed for async use with Tokio or another async runtime. Ensure your function is async and you use .await on the send() and text() methods. For complex scraping involving HTML parsing, you can combine reqwest with a crate like scraper or select. The pattern is to fetch the HTML with your proxied client, then parse it.
let html = client.get("https://example.com").send().await?.text().await?;
// Now parse `html` with your chosen HTML parsing library
If you are building a broader application, you might also need to interact with our REST API to check balance, create proxy users, or fetch usage data. Use the reqwest library itself with a Bearer token for those API calls.
Example: complete scraper with rotation
Here is a more complete example that creates multiple clients for rotating requests, targeting different locations. This pattern is useful for gathering market research data or real estate data from geographically varied sources.
use reqwest::{Client, Proxy};
use std::time::Duration;
async fn make_client(username: &str) -> Result {
let proxy = Proxy::all("http://gw.rotatingproxy.cc:7070")?
.basic_auth(username, "PASSWORD");
Client::builder()
.proxy(proxy)
.timeout(Duration::from_secs(30))
.build()
}
#[tokio::main]
async fn main() -> Result<(), Box> {
let us_client = make_client("USERNAME_net.res_cc.us").await?;
let de_client = make_client("USERNAME_net.res_cc.de").await?;
// Use clients for different geographic checks...
let us_ip = us_client.get("https://api.ipify.org").send().await?.text().await?;
println!("US exit IP: {}", us_ip);
Ok(())
}
This setup gives you flexibility to tailor your proxy configuration to the needs of your project, whether it's for social media management, AI training data collection, or website uptime monitoring.
Questions
Can I use reqwest to scrape sites like Google or Amazon?
Yes, you can use reqwest with our proxies to access sites like Google Search or Amazon. Ensure you comply with the site's terms of service, use appropriate request headers, and implement rate limiting to avoid blocks.
How do I switch between different proxy networks (residential, mobile, etc.) in the same code?
Change the <code>net.</code> option in the username string. For example, use <code>USERNAME_net.mob_cc.us</code> for mobile or <code>USERNAME_net.dc_cc.us</code> for datacenter. Build a separate client for each network configuration you need.
My requests are getting blocked even with a proxy. What should I do?
Blocks can happen due to browser fingerprinting, TLS signatures, or behavior patterns. Try adding realistic headers (User-Agent, Accept), varying your request timing, and using sticky sessions if the site expects consistent IPs. Our guide on how to avoid getting blocked has detailed advice.
Does reqwest handle proxy authentication for HTTPS CONNECT automatically?
Yes, when you use <code>Proxy::all</code> with basic authentication, reqwest handles the HTTP CONNECT tunnel and authentication for HTTPS targets automatically. No additional setup is required for HTTPS.
How can I check my remaining balance from within my Rust code?
Use reqwest to call our REST API at <code>https://rotatingproxy.cc/api/v1/balance</code> with a Bearer token from your dashboard. Parse the JSON response to get your current balance in USD. See the API documentation for the exact endpoint.
What happens if my balance runs out during a long-running job?
When your balance reaches zero, the proxy gateway will stop forwarding traffic and return an error. Your requests will fail until you top up your balance. It's good practice to monitor your balance via the API and set up alerts.
Start with one top-up, use any network
Create an account in a minute, add $40 or more, and the same balance pays for residential, mobile, datacenter and ISP traffic.