为什么这个axios put请求没有设置peoperly的标题

问题描述 投票:0回答:2

因此,我正在编写一个discord机器人,该机器人基本上使我为一堆不同的命令制作的API连接起来。不幸的是,我坚持这一看跌期权要求,并且指出了错误所在。 该请求似乎没有发送我在标头中设置的身份验证密钥。我检查了API日志,并且auth中间件拒绝了该请求,因为没有提供密钥。我将不胜感激。

  • 这是在异步函数中
  • 所有其他请求都有效,实际上我是从以前的有效副本中复制并粘贴了此标头
  • 此请求不需要正文
  • 在某种程度上相关的情况下:这在collector.on('collect', async () => {HERE})中。
let updatedUser = await axios.put(
                            `https://API-URL-GOES-HERE/api/users/${username}/loaChange`,
                            {
                                headers: {
                                    auth:
                                        'AUTH-KEY-GOES-HERE'
                                }
                            }
                        );

已收到失败的标题:

{
   host: 'API-URL-HERE.herokuapp.com',
   connection: 'close',
   accept: 'application/json, text/plain, */*',
   'content-type': 'application/json;charset=utf-8',
   'user-agent': 'axios/0.19.0',
   'x-request-id': 'REQID',
   'x-forwarded-for': 'IPADRESS',
   'x-forwarded-proto': 'https',
   'x-forwarded-port': '443',
   via: '1.1 vegur',
   'connect-time': '2',
   'x-request-start': '1577766826940',
   'total-route-time': '5',
   'content-length': '194'
 }

成功的请求:

let initialUser = await axios.get(
                        `https://API-URL-GOES-HERE/api/users/${username}`,
                        {
                            headers: {
                                auth:
                                    'AUTH-KEY-GOES-HERE'
                            }
                        }
                    );

成功获得的标题:

{
host: 'API-URL-HERE.herokuapp.com',
  connection: 'close',
   accept: 'application/json, text/plain, */*', 
  auth: 'AUTH-KEY-HERE',
   'user-agent': 'axios/0.19.0',
   'x-request-id': 'REQID',
   'x-forwarded-for': 'IPADDRESS',
  'x-forwarded-proto': 'https',
 'x-forwarded-port': '443',
   via: '1.1 vegur',
   'connect-time': '0',
   'x-request-start': '1577766773203',
   'total-route-time': '0'
 }
<<

因此,我正在编写一个discord机器人,该机器人基本上使我为一堆不同的命令制作的API连接起来。不幸的是,我坚持这一看跌期权要求,并且指出了错误所在。 ...

javascript node.js axios discord.js put
2个回答
0
投票
{ headers: {"Authorization" : `Bearer ${AUTH-KEY-GOES-HERE}`} }

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.