简体   繁体   English

如何在我的反应应用程序中包含授权标头?

[英]How can I include authorization Headers in my react-app?

On postman, I can access endpoints by adding the headers:在 postman 上,我可以通过添加标头来访问端点:

Key: Value ( I will insert fake figures for example)键:值(例如,我将插入假数字)

x-mash-auth-token: gdjsjaosh-hkds-dhjsk-hjjdbahsj

I am building a react app that allows user to search endpoints, how can I include this header in my code to grant user access on UI?我正在构建一个允许用户搜索端点的 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);
            })
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 npm 启动我的 react-app? (缺少启动脚本?) - How can i start my react-app via npm ? (start-script missing?) 为什么我无法在 google、yahoo 和 bing 搜索中索引我的 react-app? - Why I can't index my react-app on google,yahoo and bing searches? 我可以将 arguments 提供给 react-app 吗? (React 的依赖注入) - Can I give arguments to a react-app? (dependency injection with React) 我没有在我的 React-app 中获得列表项 - I am not getting the list item in my React-app 创建 React 应用程序失败。 我使用了 npm init react-app my-app - Creating React app failed. I used npm init react-app my-app 我是否需要安装 babel 才能在我的 react-app 中编写 ES6 代码? - Do I need to install babel to be able to write ES6 code in my react-app? 无论如何我可以解决这个反应应用程序问题吗? 一直无法启动开发服务器 - Is there anyway I can fix this react-app problem? Have not been able to start the development sever 为什么录像不能在我的React-app中工作? - Why isn't video recording working in my React-app? 可以有太多的事件处理程序影响React-app的性能吗? - Can too many event handlers impact the performance of a React-app? 如何避免在 react-app 的生产版本中使用 polyfill - How to avoid polyfills on production build of react-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM