1

我在用着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?;

我无法设置基本授权标头,并且代码给出了错误“缺少身份验证凭据”。

4

1 回答 1

3

正如上述评论所建议的,在标题中的“基本”之后添加了缺失的空格,解决了这个问题。

let res = self
    .client
    .post(url)
    .header("Content-type", "application/x-www-form-urlencoded")
    .header("Authorization", "Basic ".to_owned() + &secret)
    .send
    .await?;
于 2021-03-08T18:04:22.700 回答