Skip to navigation
Making a blocking POST rust requests
03.10.22
let token = "".to_string(); let client = reqwest::blocking::Client::new(); let _res = client.post("https://foo.com/token") .header("User-Agent", "Actix-web") .header("Authorization", "Bearer foobarbar=") .header("Content-Type", "application/x-www-form-urlencoded") .body("text=3071251") .send()?; let header = _res.headers().clone(); let status = _res.status().clone(); let body = _res.text()?; let mut h_dj = json::parse(&body).unwrap(); let time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(); let expires_at = h_dj["expires_in"].as_u64().unwrap() + time; h_dj["expires_at"] = expires_at.to_string().into(); let saved = fs::write("token.json", h_dj.dump())?; Ok(())
https://docs.rs/reqwest/latest/reqwest/blocking/
Reply
Anonymous
Information Epoch 1742417873
Use lower case and keep it short.
Home
Notebook
Contact us