I'm using reqwest = { version = "0.11", features = ["json"] }

impl Client {pub fn new(/*endpoint: Url*/) -> Result<Client> {Ok(Client {client: reqwest::ClientBuilder::new().build()?,})}}
let res = self.client.post(url).header("Content-type", "application/x-www-form-urlencoded").header("Authorization", "Basic".to_owned() + &secret).send.await?;let data = res.json::<Response>().await?;

I'm not able to set the basic authorization header, and the code gives the error "Missing auth credentials".

1

Best Answer


As suggested from above comments, added the missing space after "Basic" in the header, solved this problem.

let res = self.client.post(url).header("Content-type", "application/x-www-form-urlencoded").header("Authorization", "Basic ".to_owned() + &secret).send().await?;