Go言語のnet/httpを使ってクッキーを設定するため、以下のコードを書きました。
lang
1package main 2 3import "io" 4import "net/http" 5import "time" 6 7func indexHandler(w http.ResponseWriter, req *http.Request) { 8 expire := time.Now().AddDate(0, 0, 1) 9 cookie := http.Cookie{"test", "tcookie", "/", "hoge.com", expire, expire.Format(time.UnixDate), 86400, true, true, "test=tcookie", []string{"test=tcookie"}} 10 req.AddCookie(&cookie) 11 io.WriteString(w, "Hello world!") 12} 13 14func main() { 15 http.HandleFunc("/", indexHandler) 16 http.ListenAndServe(":80", nil) 17}
ところが、Cookieができません。何が間違っているのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。