如何在我的 react-app 中包含授权 Headers?
How can I include authorization Headers in my react-app?
在 postman 上,我可以通过添加 headers:
来访问端点
键:值(我会插入假数字为例)
x-mash-auth-token: gdjsjaosh-hkds-dhjsk-hjjdbahsj
我正在构建一个允许用户搜索端点的 React 应用程序,我如何在我的代码中包含此 header 以授予用户对 UI 的访问权限?
axios({
url: "API URL",
method: "GET",
data: {name: "abc"},
contentType: 'application/json',
headers: {
"Access-Control-Allow-Origin": "*",
'Accept': 'application/json',
'Content-Type': 'application/json',
'Pragma': 'no-cache',
'Authorization': 'Bearer gdjsjaosh-hkds-dhjsk-hjjdbahsj',
'Access-Control-Expose-Headers': "jwt_token"
},
responseType: 'json'
})
.then(function (response) {
successCallback(response);
})
.catch(function (error) {
errorCallback(error);
})
在 postman 上,我可以通过添加 headers:
来访问端点键:值(我会插入假数字为例)
x-mash-auth-token: gdjsjaosh-hkds-dhjsk-hjjdbahsj
我正在构建一个允许用户搜索端点的 React 应用程序,我如何在我的代码中包含此 header 以授予用户对 UI 的访问权限?
axios({
url: "API URL",
method: "GET",
data: {name: "abc"},
contentType: 'application/json',
headers: {
"Access-Control-Allow-Origin": "*",
'Accept': 'application/json',
'Content-Type': 'application/json',
'Pragma': 'no-cache',
'Authorization': 'Bearer gdjsjaosh-hkds-dhjsk-hjjdbahsj',
'Access-Control-Expose-Headers': "jwt_token"
},
responseType: 'json'
})
.then(function (response) {
successCallback(response);
})
.catch(function (error) {
errorCallback(error);
})