【发布时间】:2020-10-14 14:32:42
【问题描述】:
我正在尝试使用 axios 从我的 Vue 向 https://api.getresponse.com/v3/contacts 发送 POST 方法。我不确定为什么我一直收到 400 错误请求。我已尝试检查 Mozilla 开发工具上的“网络”选项卡,但似乎没有任何它刚刚返回给我的响应消息。
XHR 选项https://api.getresponse.com/v3/contacts [HTTP/1.1 400 错误请求 763ms]
我从 GetResponse 文档中再次确认将 Content-Type 标头添加到 application/json 并将我的 API 密钥设置为 X-Auth-Token: api-key <API_KEY>。
注意:我也收到了CORS header ‘Access-Control-Allow-Origin’ missing,但我相信它与错误 400 没有任何关系。
这是我的 Vue 文件中的一些代码 sn-ps。
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);
}
}
【问题讨论】:
标签: javascript vue.js