第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

可以使用 Postman 訪問本地端點,但不能使用 Axios

可以使用 Postman 訪問本地端點,但不能使用 Axios

躍然一笑 2021-09-17 12:58:32
我正在嘗試在我的 Javascript React 應用程序中使用 Axios 發(fā)出一個簡單的 GET 請求。此請求與 Postman 完美配合,但我無法使用 Axios。我嘗試了幾種不同的代碼變體,但都不起作用。這是最簡單的版本:  import React, { useEffect } from 'react';  import { Auth } from 'aws-amplify';  useEffect(() => {    const fetchRoles = async () => {      var authToken;      Auth.currentSession()        .then(data => {           authToken = data.getAccessToken().getJwtToken();        })        .catch(err => console.log(err));      var config = {        headers: { Authorization: "Bearer " + authToken}      };      var bodyParameters = {        key: "value"      };      axios.get("http://127.0.0.1:5000/accounts/roles", bodyParameters, config)        .then(response => {          console.log(response);        })        .catch(error => {          console.log(error);        });    fetchRoles();  }我每次得到的錯誤是:127.0.0.1 - - [19/Aug/2019 14:12:27] "GET /account_management/roles HTTP/1.1" 401 -Exception getting user An error occurred (InvalidParameterException) when calling the GetUser operation: 1 validation error detected: Value at 'accessToken' failed to satisfy constraint: Member must satisfy regular expression pattern: [A-Za-z0-9-_=.]+我不明白這個錯誤,因為我已經(jīng)根據(jù)這個 RegEx 表達式檢查了 Auth Token 并且它是有效的。
查看完整描述

2 回答

?
蕭十郎

TA貢獻1815條經(jīng)驗 獲得超13個贊

解決了,我覺得很愚蠢。

作為 Axios 的新手,我從字面上復制了代碼。示例 Axios 代碼用于 POST。我突然意識到通過bodyParameters. 刪除它和 GET 工作!

順便說一句,我希望這對將來的其他人有所幫助,在 Auth Token 前面加上“Bearer”是完全可選的。這兩個工作正常:

  headers: { Authorization: "Bearer " + authToken}

  headers: { Authorization: authToken}


查看完整回答
反對 回復 2021-09-17
  • 2 回答
  • 0 關注
  • 811 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號