【问题标题】:Can't have Authorized Axios post request to Raindrop API不能授权 Axios 向 Raindrop API 发布请求
【发布时间】:2021-01-09 09:04:30
【问题描述】:

我正在尝试为我的一个雨滴集合构建一个简单的获取应用程序并将其显示在一个项目中。

我正在使用“测试令牌”,所以我现在不必制作所有授权内容。

所有信息(access_token、collection_id)都显示良好。

useEffect(() => {
    if (accessToken !== null) {
        const headers = {
            Authorization: `Bearer ${accessToken}`
        };

        axios.post(
            `https://api.raindrop.io/rest/v1/collection/${COLLECTION_ID}`,
            { headers: headers }
        ).then(console.log).catch(console.log);
    }
},[])

我正在注入的标头显示在 https 的 Request Payload 中

但是响应只是显示 Unauthorized...

有人曾经尝试过这样做并且可以帮助我吗?

谢谢!

【问题讨论】:

    标签: api request axios http-post


    【解决方案1】:

    根据axios post请求,第二个参数是body,第三个是headers。

    将您的请求更改为,

            axios.post(
                `https://api.raindrop.io/rest/v1/collection/${COLLECTION_ID}`,
                {}, // request body, since post request.
                { headers: headers }
            ).then(console.log).catch(console.log);
    
    

    【讨论】:

      猜你喜欢
      • 2020-02-11
      • 2020-01-19
      • 2020-07-17
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      相关资源
      最近更新 更多