Vue JS,Axios:403错误的访问令牌,即使它是正确的

时间:2019-10-20 14:46:33

标签: vue.js axios

我的Vue应用程序具有一个电子邮件订阅字段,该字段具有一个提交按钮,该按钮将电子邮件发送到我的API。单击提交按钮时出现以下错误:

>>> range(6)
[0, 1, 2, 3, 4, 5]

>>> len(range(6))
6

我100%确定我的API密钥正确,并且指向我的API的链接也是如此。

这是我的代码:

{"meta":{"status":false,"error":{"code":0,"message":"Wrong access token.","customer_message":""}},"data":[]}

我不确定我在做什么错。我非常感谢您的帮助。谢谢!

2 个答案:

答案 0 :(得分:0)

您可以添加标题对象

 methods: { submitEmail() {   axios
        .post(
          "https://my_api.com/registrations?access_token=my_api_key"
          {
            language: this.language,
            user_email: this.postEmail,
            auth: {
              username: "username",
              password: "password"
            }
          }, 
{  headers: { 'Content-Type': 'application/json', 'Authorization': 'JWT fefege...' }  } )  .then(response =>  { // console.log(response); })  .catch(function(error) {}); } }

答案 1 :(得分:0)

我删除了auth部分,它起作用了!身份验证部分是这样的:

auth: {
              username: "username",
              password: "password"
            }