简体   繁体   English

如何在发出 GET 请求时发送 jwt 令牌以进行验证

[英]How to send jwt token for verfication while making a GET request

Basically I want to send a GET request which contains a header Authorization= jwt and then at server side this JSON web token is verified and a page should be rendered but if I make request using AXIOS or fetch than response is not render and if I use simple a tag to make request than how would I add header to it.基本上,我想发送一个包含标题 Authorization= jwt 的 GET 请求,然后在服务器端验证此 JSON Web 令牌并应呈现页面,但如果我使用 AXIOS 或 fetch 发出请求,则不会呈现响应,如果我使用一个简单的标签来发出请求,而不是我如何向它添加标头。 I am using NodeJS, ejs, express to render and vanilla JavaScript我正在使用 NodeJS、ejs、express 来渲染和 vanilla JavaScript

Use following code before sending axios request.在发送 axios 请求之前使用以下代码。

axios.defaults.headers.common["Authorization"] = jwt;

Full code of express application with axios requests could be seen here可以在此处查看带有 axios 请求的 express 应用程序的完整代码

This is how we can do with fetch这就是我们如何使用 fetch

fetch("http://....url", {
    method:"GET",
    headers:{
    ContentType:"Application/json",
    Authorization: jwt
    }
  }
).then(res => )

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM