首页 > 其他 > 详细

Go Cookie 练习

时间:2014-08-12 00:37:53      阅读:297      评论:0      收藏:0      [点我收藏+]
package main

import (
    "io"
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/", Cookie)
    http.HandleFunc("/2", Cookie2)
    http.ListenAndServe(":8080", nil)
}

func Cookie(rw http.ResponseWriter, req *http.Request) {
    c := &http.Cookie{
        Name:  "mycookie",
        Value: "hello world",
        Path:  "/",
        //Domain: "localhost",
    }
    http.SetCookie(rw, c)

}
func Cookie2(rw http.ResponseWriter, req *http.Request) {
    //var c1 []*http.Cookie
    c1, err := req.Cookie("mycookie")
    if err != nil {
        //io.WriteString(rw, err.Error())
        log.Printf(err.Error())
        return
    }

    io.WriteString(rw, c1.Value)

}


主要是测试新版本cookie里有空格的问题,在go1.3已经修复

Go Cookie 练习,布布扣,bubuko.com

Go Cookie 练习

原文:http://www.cnblogs.com/hellosun/p/3906074.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!