springboot 获取请求 / 响应 接收和设置请求头 、请求码的方法
ResponseEntity处理响应信息
https://blog.csdn.net/neweastsun/article/details/81142870/
https://blog.csdn.net/kangweijian/article/details/110189922
方法一:
塞单个请求头
1 2 3 4 5 6 7 8 9 10 | @GetMapping ( "/bbb" ) public ResponseEntity<Map> delete_User2 (HttpServletRequest HttpServletRequest) { HttpHeaders headers = new HttpHeaders(); headers.add( "Custom-Header" , "foo" ); Map m1 = new HashMap(); m1.put( "name" , "张三" ); return ResponseEntity.status( 302 ).header( "location" , "http://202.108.22.5/" ).body(m1); } |
塞多个请求头 (这个最好)
1 2 3 4 5 6 7 8 9 10 11 | @GetMapping ( "/bbb" ) public ResponseEntity<Map> delete_User2 (HttpServletRequest HttpServletRequest) { HttpHeaders headers = new HttpHeaders(); headers.add( "Custom-Header" , "foo" ); headers.add( "Custom-Header222" , "foo222" ); Map m1 = new HashMap(); m1.put( "name" , "张三" ); System.out.print(m1); log.info(HttpServletRequest.getHeader( "lucax" )); return ResponseEntity.status( 302 ).headers(headers).body(m1); } |
方法二:
1 2 3 4 5 6 7 8 | @GetMapping ( "/bbb" ) public ResponseEntity<Map> delete_User2 (HttpServletRequest HttpServletRequest) { HttpHeaders headers = new HttpHeaders(); headers.add( "Custom-Header" , "foo" ); headers.add( "Custom-Header222" , "foo222" ); log.info(HttpServletRequest.getHeader( "lucax" )); return new ResponseEntity( "Custom header set" , headers, HttpStatus.resolve( 300 )); } |
获取请求过来的请求头,见:
接收请求头信息和发送请求的去这里看看
https://www.cnblogs.com/kaibindirver/p/15398815.html
请求ip啥的 下面这篇文章有
https://blog.csdn.net/qq_41767337/article/details/89144733
分类:
SpingBoot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2019-11-08 pandas从入门到上楼(可以结合request做图表)
2018-11-08 访问https请求出现警告,去掉警告的方法
2018-11-08 find 和 find_all 用法
2018-11-08 beautifulsoup 基本语法 含class属性查找小技巧class_