[英]Trying to use axios to query an API endpoint
Hey I'm trying to get this mod.io example working.嘿,我正在尝试让这个 mod.io 示例工作。 Here is an example curl they give这是他们给出的卷曲示例
curl -X POST https://api.mod.io/v1/oauth/emailrequest \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'api_key=0d0ba6756d032246f1299f8c01abc424' \
-d 'email=john.snow@westeros.com'
I am trying to add that to my Vue JS app but it returns a 401 error.我试图将它添加到我的 Vue JS 应用程序中,但它返回 401 错误。 Can anyone see anything wrong?任何人都能看出有什么不对吗
methods: {
loginUser() {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
console.log(this.email) //Works
const data = {
api_key: "0d0ba6756d032246f1299f8c01abc424",
email: this.email
}
axios
.post('https://api.mod.io/v1/oauth/emailrequest', data, {
headers: headers
})
.then(response => {
console.log(response);
})
.catch((error) => {
console.log(error);
})
}
The API and email are from the docs so feel free to have a try with it. API 和电子邮件来自文档,因此请随意尝试。 This is where i am struck这是我被震撼的地方
Is it possibly my localhost not being SSL?我的本地主机可能不是 SSL 吗?
I knew I was close....我知道我很接近......
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
const data = "api_key=0d0ba6756d032246f1299f8c01abc424&email="+this.email;
axios
.post('https://api.mod.io/v1/oauth/emailrequest', data, {
headers: headers
})
.then(response => {
console.log(response);
})
.catch((error) => {
console.log(error);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.