Ive mainly been experimenting with the reqwest module over the past few days to see what i can accomplish, but i came over a certain problem which im not able to resolve. Im trying to retrieve the a response headers value after doing a post request. The code in which i tried is
extern crate reqwest;
fn main() {
let client = reqwest::Client::new();
let res = client
.post("https://google.com")
.header("testerheader", "test")
.send();
println!("Headers:\n{:#?}", res.headers().get("content-length").unwrap());
}
This code seems to return this error
error[E0599]: no method named `headers` found for opaque type `impl std::future::Future` in the current scope
The latest
reqwest
isasync
by default, so in your exampleres
is a future, not the actual response. Either you need toawait
the response or usereqwest
's blocking API.async/await
In your Cargo.toml add
tokio
as a dependency.Use
tokio
as the async runtime andawait
the response.Blocking API
In your Cargo.toml enable the
blocking
feature.Now you can use the
Client
from thereqwest::blocking
module.