简体   繁体   English

GetResponse 400 错误请求

[英]GetResponse 400 Bad Request

I'm trying to send a POST method to https://api.getresponse.com/v3/contacts from my Vue using axios.我正在尝试使用 axios 从我的 Vue 向https://api.getresponse.com/v3/contacts发送 POST 方法。 I'm unsure why I kept getting a 400 Bad Request.我不确定为什么我一直收到 400 Bad Request。 I've tried checking the Network tab on Mozilla dev tools but there doesn't seem to have any Response message it just returned me.我试过检查 Mozilla 开发工具上的网络选项卡,但似乎没有任何响应消息它刚刚返回给我。

XHR OPTIONS https://api.getresponse.com/v3/contacts [HTTP/1.1 400 Bad Request 763ms] XHR 选项https://api.getresponse.com/v3/contacts [HTTP/1.1 400 Bad Request 763ms]

I have double confirm from GetResponse documentation to add the Content-Type header to application/json and to set my API key as X-Auth-Token: api-key <API_KEY> .我从 GetResponse 文档中双重确认将 Content-Type 标头添加到application/json并将我的 API 密钥设置为X-Auth-Token: api-key <API_KEY>

NOTE : I am also getting CORS header 'Access-Control-Allow-Origin' missing but I believe it does not have anything to do with the Error 400.注意:我也CORS header 'Access-Control-Allow-Origin' missingCORS header 'Access-Control-Allow-Origin' missing但我相信它与错误 400 没有任何关系。

Here are some code snippets from my Vue file.这是我的 Vue 文件中的一些代码片段。

axios-config.js axios-config.js

const instance = axios.create({
  baseURL: process.env.VUE_APP_GET_RESPONSE_BASE_URL,
  headers: {
    'Content-Type': 'application/json',
    'X-Auth-Token': `api-key ${process.env.VUE_APP_GET_RESPONSE_API_KEY}`,
  }
});

Vue视图

import axios from "@/services/axios-config.js";

user: {
  name: "",
  campaign: {
    campaignId: `${process.env.VUE_APP_GET_RESPONSE_CAMPAIGN_ID}`
  },
  email: "",
  customFieldValue: {
    customFieldId: "interest",
    value: []
  }
}

async callSubscribeAPI() {  
  try{
    const response = await axios.post("/contacts",this.user);

    console.log(response);
  }catch(error){
    console.log("error");
    console.log(error);
  }
}

This works for me:这对我有用:

(async() => {

  const url = 'https://api.getresponse.com/v3/accounts';

  const payload = await axios({
    method: 'get',
    url,
    headers: {
      "X-Auth-Token": "api-key 12345*****",
      "content-type": "application/json"
    }    
  });

  console.log("payload", payload.data);

})()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM