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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM