关于Cookie

 

1.测试:Cookie和端口无关,和ip或域名有关

localhost:81 设置cookie                      :     请求发现请求头有cookie

localhost:82 不设置cookie                   :     请求发现请求头有cookie

192.168.199.225:82 不设置cookie      :     请求发现请求头无cookie

localhost:81

    @GetMapping("/health")
    public void health(HttpServletRequest request, HttpServletResponse response) {
        //设置1
       response.addHeader("Set-Cookie","hello ytf 81");

        //查看
        Cookie[] cookies = request.getCookies();
        if(cookies != null)
            for(Cookie c : cookies){
                String name = c.getName();//获取Cookie名称
            }

    }

 

localhost:82

    @GetMapping("/health")
    public void health(HttpServletRequest request, HttpServletResponse response) {
        //设置1
//        response.addHeader("Set-Cookie","hello 81");

        //设置2
//        Cookie cookie = new Cookie("jieguo","true");
//        response.addCookie(cookie);

        //查看
        Cookie[] cookies = request.getCookies();
        if(cookies != null)
            for(Cookie c : cookies){
                String name = c.getName();//获取Cookie名称
            }

    }

 

 

 

 192.168.199.225:82

 

 

2.同源策略

 

posted @ 2022-11-29 19:44  Peter.Jones  阅读(21)  评论(0编辑  收藏  举报