I have a few questions too:
2- How to make sure TCP connection is not closed and keep it alive ?
3- What can i do else to make faster request ?
The reason of these all is i want to make fast request.
Here is the code that i used
use reqwest::{redirect::Policy, Client, ClientBuilder,Version};
use serde_json::Value;
use std::time::Duration;
use std::time::Instant;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client= ClientBuilder::new()
.tcp_nodelay(true)
.redirect(Policy::none())
.build().unwrap();
let mut counter = 0;
let mut flag = true;
let mut total = 0.0;
while flag {
if counter==20 {
flag = false
}
else{
let response_time = marketplace(&client).await?;
println!("Difference->{:?}",response_time.as_secs_f64());
total += response_time.as_secs_f64();
counter +=1
}
}
println!("Total fetch reqwest {} ",total);
println!("Count reqwest {}",counter);
println!("Avarage Time reqwest {}",total/counter as f64);
Ok(())
}
pub async fn marketplace(client: &Client) -> Result<Duration,reqwest::Error> {
let now = Instant::now();
let resp = client
.get("https://api.shadowpay.com/api/market/get_items?currency=USD&sort_column=price_rate&sort_dir=desc&search=&stack=false&offset=150&limit=50&sort=desc&game=csgo")
.version(Version::HTTP_11)
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36")
.header("accept-language", "tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7")
.header("authority", "api.shadowpay.com")
.header("origin", "https://shadowpay.com/")
.header("authorization", "Bearer")
.header("referer", "https://shadowpay.com/")
.send()
.await?;
println!("{:?}",resp.version());
let result = resp.json::<Value>()
.await?;
let elapsed = now.elapsed();
Ok(elapsed)
}