gpt4 book ai didi

javascript - 发出 http 请求

转载 作者:行者123 更新时间:2023-12-03 00:43:40 32 4
gpt4 key购买 nike

我想在带有或不带有 Axios 的 React 应用程序上发出如下所示的 get 请求。但我不知道如何为此添加我的身份验证 token 。

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

关于javascript - 发出 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53338352/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com