找回密码
 立即注册
查看: 6|回复: 0

20,携带头部信息进行验证

[复制链接]

223

主题

6

精华

227

金币

技术维护QQ:515138

积分
484
发表于 昨天 18:16 | 显示全部楼层 |阅读模式
案例如下:

  1. package com.jinhei.controller;
  2. import com.jinhei.pojp.Result;
  3. import com.jinhei.utils.JwtUtils;
  4. import jakarta.servlet.http.HttpServletResponse;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.RequestHeader;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import java.util.Map;
  10. @RestController
  11. @RequestMapping("/article")
  12. public class ArticleController {
  13.     @GetMapping("/list")
  14.     public Result list(@RequestHeader(name = "Authorization") String token, HttpServletResponse response){
  15.         System.out.println(token);
  16.         // 验证token
  17.         try {
  18.             Map<String, Object> claims = JwtUtils.parseJWT(token);
  19.         } catch (Exception e) {
  20.             // HTTP响应码 401
  21.             response.setStatus(401);
  22.             return Result.error("未登录");
  23.         }
  24.         return Result.success("article list");
  25.     }
  26. }
复制代码




上一篇:19,JWT令牌,登录认证jjwt-api 0.12.6
下一篇:21,拦截器interceptors,配置注册拦截器,登录成功验证整合JWT
网站建设,公众号小程序开发,系统定制,软件App开发,技术维护【联系我们】手机/微信:17817817816 QQ:515138

QQ|Archiver|自丢网 ( 粤ICP备2024252464号-1 )

GMT+8, 2026-3-2 06:23

专注于网站建设,公众号小程序制作,商城小程序,系统定制,软件App开发

【联系我们】手机/微信:17817817816 QQ:515138

快速回复 返回顶部 返回列表