【问题标题】:Making a http request [duplicate]发出http请求[重复]
【发布时间】:2019-04-19 16:06:43
【问题描述】:

我想在我的 React App 上使用或不使用 Axios 发出如下所示的获取请求。但我不知道如何为此添加我的身份验证令牌。

curl -X GET https://server.url/acp-service/sites -H 'Content-Type: application/json' -H 'X-Authorization: eyJhbGciOiJIUzUxMiJ9.eyJ...long.string.here'

你能帮帮我吗?

【问题讨论】:

    标签: javascript reactjs xmlhttprequest


    【解决方案1】:

    使用fetch()

    (async () => {
      const rawResponse = await fetch(' https://server.url/acp-service/sites', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
          'X-Authorization': 'your_auth_string'
        }
      });
      const content = await rawResponse.json();
    
      console.log(content);
    })();
    

    【讨论】:

    • 当问题被标记为xmlhttprequest时为什么“使用fetch()”?!
    猜你喜欢
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    相关资源
    最近更新 更多