【问题标题】: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);
})();