使用axios進行API端點查詢的嘗試
P粉340264283
P粉340264283 2023-09-09 19:50:48
0
1
574

嗨,我正在嘗試讓這個mod.io範例工作。這是他們給的一個curl範例

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'

我正在嘗試將其添加到我的Vue JS應用程式中,但返回401錯誤。有人能看到有什麼問題嗎?

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);
  })
}

API和電子郵件來自文檔,所以請隨意嘗試。 這就是我遇到的問題

可能是我的本機沒有SSL嗎?

P粉340264283
P粉340264283

全部回覆(1)
P粉056618053

我知道我離成功很近....

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);
  })
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!