Last active
August 17, 2025 08:26
-
-
Save InShade/f2cfb8eb1df367a98b9f4e09bfe46e8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use reqwest::header; | |
use reqwest::ClientBuilder; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
println!("\n[ - - - - - - - - -"); | |
let mut headers = header::HeaderMap::new(); | |
headers.insert("X-MY-HEADER", header::HeaderValue::from_static("asdfgh")); | |
headers.insert("COOKIE", header::HeaderValue::from_static("__test=123456")); | |
// `Client` | |
/* | |
let client = reqwest::Client::builder() | |
.default_headers(headers) | |
.build()?; | |
*/ | |
// `ClientBuilder` | |
let client = ClientBuilder::new().build()?; | |
// `RequestBuilder` | |
let r :reqwest::Request = client.get("http://dadou.run/my").headers(headers).build()?; | |
println!("client_Headers: {:#?}", r.headers()); | |
// `Response` | |
let resp :reqwest::Response = client.execute(r).await?; | |
println!("\n Status: {} \n", resp.status()); | |
println!("server_Headers: {:#?}", resp.headers()); | |
let body :String = resp.text().await?; | |
println!("\nBody: {}", body); | |
println!("- - - - - - - - - ]\n"); | |
Ok(()) | |
} | |
/* | |
[ - - - - - - - - - | |
client_Headers: { | |
"x-my-header": "asdfgh", | |
"cookie": "__test=123456", | |
} | |
Status: 200 OK | |
server_Headers: { | |
"server": "nginx", | |
"date": "Sun, 17 Aug 2025 07:22:45 GMT", | |
"content-type": "application/json", | |
"content-length": "407", | |
"connection": "keep-alive", | |
"vary": "Accept-Encoding", | |
} | |
Body: {"request_id": "719c8ef013233fd7f12b8039666250ef","request_method": "GET","request_time": "0.000","request_body": "","request_l | |
ength": "101","request_time": "0.000","user_agent": "","via": "","x_forwarded_for": "","proxy_protocol_addr": "","proxy_protocol_port | |
": "","client_ip": "185.228.105.43","client_port": "2191","server": "Parrot/1.0.2","server_protocol": "HTTP/1.1","at": "2025-08-17T15 | |
:22:45+08:00"} | |
- - - - - - - - - ] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment