问题描述
我看到了很多有关jwt身份验证的教程,但是每个视频制作者都使用Postman来显示正在发生的事情,并且他们在请求Postman中的URL时在headers部分中传递了header.我试图用JavaScript来做到这一点,但是我却做不到.
I saw many tutorials on jwt authentication but every video maker uses Postman to show what's happening and they pass on the header in the headers section while requesting a URL in Postman. I tried to do it with JavaScript but I was not able to do it.
我想进行jwt身份验证,但是在生成令牌后,我将其发送到客户端以将其用于其他请求,但是尝试了几次后却没有这样做.我还尝试在服务器端设置req.headers,但是它没有实现我想要的功能.
I want to do jwt authentication but after token generation, I send it to client side to use it for further requests but I failed to do so after trying it a few times. I also tried to set req.headers in server side but it didn't do what I wanted to..
我想为令牌生成后的每个请求设置请求标头,以用于形式"Bearer {token}"的身份验证.如何用JS做到呢?
I want to set request headers for authentication of the form "Bearer {token}" for every request after token generation. How to do it with JS??
我最担心的是每个教程都是通过邮递员完成的,但是他们没有展示如何在自己的应用程序中实现它.我希望我的问题很清楚.
What I am most concerned about is that every tutorial does it with postman but they didn't show how they implemented it in their own app. I hope my question is clear.
推荐答案
您可以像这样轻松地在http请求中添加标头
You can easily add header on your http request like that
已在此处解决Node.JS:如何使用请求模块发送带有表单数据的标头
这篇关于在Node.js中请求页面时如何设置标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!