-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathset_proxies.rs
48 lines (36 loc) · 1.4 KB
/
set_proxies.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use rquest::{Client, Impersonate};
#[tokio::main]
async fn main() -> Result<(), rquest::Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.init();
// Build a client to impersonate Chrome130
let mut client = Client::builder()
.impersonate(Impersonate::Chrome130)
.build()?;
// Use the API you're already familiar with
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
// Set the proxies
{
let proxy = rquest::Proxy::all("socks5h://abc:123@127.0.0.1:6153")?;
client.as_mut().proxies(vec![proxy]);
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
}
// Clear the proxies
{
client.as_mut().proxies(None);
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
}
Ok(())
}