首页 > 代码库 > Go Cookie 练习

Go Cookie 练习

package mainimport (    "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已经修复