An ergonomic, batteries-included HTTP Client for Rust.
- Plain bodies, JSON, urlencoded, multipart
- Customizable redirect policy
- HTTP Proxies
- HTTPS via BoringSSL
- WebSocket
- Cookie Store
- WASM
- Changelog
A fork of reqwest used to impersonate the Chrome browser / OkHttp. Inspired by curl-impersonate.
This asynchronous example uses Tokio and enables some
optional features, so your Cargo.toml
could look like this:
[dependencies]
tokio = { version = "1", features = ["full"] }
reqwest_impersonate = { version = "0.11", default-features = false, features = [
"boring-tls",
"impersonate"
] }
Or WebSocket:
[dependencies]
tokio = { version = "1", features = ["full"] }
reqwest_impersonate = { version = "0.11", default-features = false, features = [
"boring-tls",
"impersonate",
"websocket",
] }
And then the code:
use std::error::Error;
use reqwest_impersonate as reqwest;
use reqwest::impersonate::Impersonate;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Build a client to mimic Chrome120
let client = reqwest::Client::builder()
.impersonate(Impersonate::Chrome120)
.danger_accept_invalid_certs(true)
.enable_ech_grease(true)
.permute_extensions(true)
.cookie_store(true)
.build()?;
// Use the API you're already familiar with
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
let resp = client
.post("https://chat.openai.com/backend-api/conversation")
.send().await?;
println!("{}", resp.text().await?);
Ok(())
}
And then the websocket code:
use reqwest_impersonate as reqwest;
use std::error::Error;
use tungstenite::Message;
use futures_util::{SinkExt, StreamExt, TryStreamExt};
use reqwest::{impersonate::Impersonate, Client};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let websocket = Client::builder()
.impersonate_websocket(Impersonate::Chrome120)
.build()?
.get("wss://echo.websocket.org")
.upgrade()
.send()
.await?
.into_websocket()
.await?;
let (mut tx, mut rx) = websocket.split();
tokio::spawn(async move {
for i in 1..11 {
tx.send(Message::Text(format!("Hello, World! #{i}")))
.await
.unwrap();
}
});
while let Some(message) = rx.try_next().await? {
match message {
Message::Text(text) => println!("received: {text}"),
_ => {}
}
}
Ok(())
}
On Linux:
- OpenSSL with headers. See https://docs.rs/openssl for supported versions
and more details. Alternatively you can enable the
native-tls-vendored
feature to compile a copy of OpenSSL.
On Windows and macOS:
- Nothing.
Reqwest uses rust-native-tls, which will use the operating system TLS framework if available, meaning Windows and macOS. On Linux, it will use OpenSSL 1.1.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.