zoukankan      html  css  js  c++  java
  • springboot 获取请求 / 响应 接收和设置请求头 、请求码的方法

    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

  • 相关阅读:
    linux常用命令-新手入门
    centos-1908安装步骤
    存储过程和函数的一些范例
    在iis7上如何配置来看到asp报错
    如何在ashx页面获取Session值
    SQL--create Table
    NET内存持续增长问题排查
    Socket之服务调用
    编程心得
    vs中无法查找或打开PDB文件
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/15524830.html
Copyright © 2011-2022 走看看