springboot 获取请求 / 响应 接收和设置请求头 、请求码的方法
2023-09-27 14:25:19 时间
ResponseEntity处理响应信息
https://blog.csdn.net/neweastsun/article/details/81142870/
https://blog.csdn.net/kangweijian/article/details/110189922
方法一:
塞单个请求头
@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); }
塞多个请求头 (这个最好)
@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); }
方法二:
@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
相关文章
- springboot工程的结构
- springboot+mybaits的二级缓存的案例
- 在springboot工程中打包制定main主类执行
- springboot 的响应式编程-webflux
- SpringBoot自动配置xxxAutoConfiguration 的使用
- SpringBoot @Transactional的rollbackFor属性
- TOC 1. TODO springboot优雅关机
- SpringBoot-@RequestParam
- springboot--ResponseEntity修改返回的 请求头 和 响应码 和 响应体的方法
- 【Springboot之切面编程】注解实现接口防刷
- [SpringBoot系列]多环境开发与日志
- SpringBoot整合表单验证注解@Validated,以及分组验证
- springboot整合ElasticSearch-7.16.2(看完即入门)
- SpringBoot:如何优雅地进行响应数据封装、异常处理?
- SpringBoot读取yml中的配置,并分离配置文件