Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发出http请求_Javascript_Reactjs_Xmlhttprequest - Fatal编程技术网

Javascript 发出http请求

Javascript 发出http请求,javascript,reactjs,xmlhttprequest,Javascript,Reactjs,Xmlhttprequest,我想在我的React应用程序(带或不带Axios)上发出如下get请求。但我不知道如何添加我的身份验证令牌 curl -X GET https://server.url/acp-service/sites -H 'Content-Type: application/json' -H 'X-Authorization: eyJhbGciOiJIUzUxMiJ9.eyJ...long.string.here' 你能帮我吗?使用 当问题被标记时,为什么要“使用fetch()?”?! (async (

我想在我的React应用程序(带或不带Axios)上发出如下get请求。但我不知道如何添加我的身份验证令牌

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

使用

当问题被标记时,为什么要“使用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);
})();