zoukankan      html  css  js  c++  java
  • Cookie

    一、Cookie介绍

    通过Set-Cookie设置

    下次请求会自动带上

    键值对,可以设置多个

    二、Cookie属性

    max-age和expires设置过期时间

    Secure只在https的时候发送

    HttpOnly无法通过document.cookie访问

    三、Cookie的使用方式

     Server.js

    const http = require('http');
    const fs = require('fs')
    
    http.createServer(function(request, response){
        console.log('request com', request.url)
        if(request.url === "/"){
            const html = fs.readFileSync('test.html','utf8')
            response.writeHead(200,{
                'Content-Type':'text/html',
                'Set-Cookie':'id=123456'
            })
            response.end(html)
        }
    
    
        
    
    
    }).listen(8888);
    
    console.log('server listening on 8888')
    
     
    设置HttpOnly,JS将无法访问abc这个Cookie值
    'Set-Cookie':['id=123456; max-age=2', 'abc=456; HttpOnly']

      

    test.html

    <html>
        <head>
            <title>Document</title>
        </head>
        <body>
            <div>Content</div>
        </body>
    
        <script>
            console.log(document.cookie);
        </script>
        
        
    </html>
    

      

    访问,可以看到设置的Cookei

  • 相关阅读:
    springboot(6)-热部署
    springboot(5)-文件上传
    ubuntu修改tomcat使用的jdk
    jstack使用
    HeapAnalyzer如何使用
    查看linux下tomcat使用的jdk版本
    ubuntu-tomcat安装目录
    vi命令
    211java-jdk安装记录
    linux的java安装目录
  • 原文地址:https://www.cnblogs.com/linlf03/p/10505211.html
Copyright © 2011-2022 走看看