我试图使用axios从Vue向https://api.getresponse.com/v3/contacts发送POST方法。我不知道为什么我总是收到一个400坏的请求。我试过检查Mozilla上的Network选项卡,但似乎没有任何响应消息,它只是返回了我。
XHR选项https://api.getresponse.com/v3/contacts HTTP/1.1 400坏请求763 Bad
我已经从GetResponse文档中进行了双重确认,将内容类型头添加到application/json中,并将我的API键设置为X-Auth-Token: api-key <API_KEY>。
注意到:我也得到了CORS header ‘Access-Control-Allow-Origin’ missing,但我相信它与错误400没有任何关系。
以下是我的Vue文件中的一些代码片段。
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);
}
}发布于 2021-03-11 11:47:05
这对我来说很管用:
(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);
})()https://stackoverflow.com/questions/64355584
复制相似问题