cookie数据结构介绍

cookie数据结构介绍

a. Expires,cookie过期时间,使用绝对时间。比如2018/10/10 10:10:10
b. MaxAge,cookie过期时间,使用相对时间,比如300s
c. Secure属性,是否需要安全传输,为true时只有https才会传输该cookie
Go语言cookie的基本操作
d. HttpOnly属性,为true时,不能通过js读取该cookie的值

golang读取cookie

a. 读取单个cookie, http.Request.Cookie(key string)

b. 读取所有cookie, http.Request.Cookies()

golang设置cookie

a. cookie := http.Cookie{Name: "username", Value: "astaxie", Expires: expiration}
b. http.SetCookie(w, &cookie)

package main

import (
"fmt"
"net/http"
) func indexHandle(w http.ResponseWriter, r *http.Request) { /*cookies := r.Cookies()
for index, cookie := range cookies {
fmt.Printf("index:%d cookie:%#v\n", index, cookie)
}*/
c, err := r.Cookie("sessionid")
fmt.Printf("cookie:%#v, err:%v\n", c, err) cookie := &http.Cookie{
Name: "sessionid",
Value: "lkjsdfklsjfklsfdsfdjslf",
MaxAge: ,
Domain: "localhost",
Path: "/",
} http.SetCookie(w, cookie) //在具体数据返回之前设置cookie,否则cookie种不上
w.Write([]byte("hello"))
} func main() {
http.HandleFunc("/", indexHandle)
http.ListenAndServe(":9090", nil)
}

Go语言cookie的基本操作的更多相关文章

  1. 动态加载多国语言 ---- cookie + 浏览器

    一.多国语言缩写列表 因为涉及到浏览器的可接收语言,所以需要知道各个国家的语言缩写. 这个百度一下即可. en 英文 en_US 英文 (美国) ar 阿拉伯文 ar_AE 阿拉伯文 (阿拉伯联合酋长 ...

  2. tornado框架&三层架构&MVC&MTV&模板语言&cookie&session

    web框架的本质其实就是socket服务端再加上业务逻辑处理, 比如像是Tornado这样的框架. 有一些框架则只包含业务逻辑处理, 例如Django, bottle, flask这些框架, 它们的使 ...

  3. Go语言 Cookie的使用

    首先看看Cookie的结构体 type Cookie struct { Name string Value string Path string // optional Domain string / ...

  4. Flask里面的cookie的基本操作

    #cookie相关操作,依赖于make_response #调用cookie依赖request模块 from flask import Flask,make_response,request #建立对 ...

  5. cookie的基本操作

    设置,读取,删除 var odate=new Date(); odate.setDate(odate.getDate()+14); document.cookie='user=blue;expires ...

  6. 理解线程3 c语言示例线程基本操作

    Table of Contents 1. 基本线程的动作 1.1. 设置线程属性 1.1.1. 设置脱离状态 1.1.2. 设置调度属性 1.2. 取消线程 1.3. 主线程创建多个线程示例 2. 了 ...

  7. 【数据结构】C语言栈的基本操作

    #include<stdio.h> #include<stdlib.h> #include<malloc.h> //定义节点 struct Node { int d ...

  8. c语言文件的基本操作

    c语言对文件的操作主要分为:按字符操作,按行操作,按内存块操作 主要的函数: fopen(): FILE * fopen(_In_z_ const char * _Filename, _In_z_ c ...

  9. C语言链表的基本操作

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

随机推荐

  1. System.IO.Directory.cs

    ylbtech-System.IO.Directory.cs 1.返回顶部 1. #region 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, Pub ...

  2. os.path.dirname(__file__)使用、Python os.path.abspath(__file__)使用

    python中的os.path.dirname(__file__)的使用 - CSDN博客https://blog.csdn.net/u011760056/article/details/469698 ...

  3. low版九九乘法表

    # while循环实现九九乘法表num_one = 1while num_one <= 9: num_two = 1 while num_two <= num_one: print(&qu ...

  4. Neo4j-Apoc

    Neo4j-Apoc APOC https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_virtual_nodes_rels 提供的函数 存储过 ...

  5. SF Symbols 使用

    伴随着WWDC 2019 的举办,对于程序员而言 ,无疑SwiftUI 推出 是比较令人兴奋的一件事情, 其中在SwiftUI 使用之中, 我们经常使用以下系统图片 Image(systemName: ...

  6. 使用Image作为BackgroundColor 使用

    https://www.hackingwithswift.com/example-code/uicolor/how-to-use-an-image-for-your-background-color- ...

  7. UMP系统架构 RabbitMQ

  8. Android开发 EditText的开发记录

    设置显示内容与隐藏内容 if (isChecked){ editPassword.setTransformationMethod(HideReturnsTransformationMethod.get ...

  9. Loadrunner系列学习--Loadrunner架构(1)

    Loadrunner系列学习--Loadrunner架构(1) 最近在学习Loadrunner,发现一个英文网站http://www.wilsonmar.com/1loadrun.htm里面介绍的比较 ...

  10. datetime与timestamp相互转换

    select unix_timestamp('2019-12-05 12:26:35'); );