package main
import "net/http"
func param(res http.ResponseWriter, req *http.Request) {
//fmt.Println("res1",res)
//res.Header().Set("Trailer", "AtEnd1, AtEnd2")
//res.Header().Set("ttt", "ddd")
//res.Header().Set("qqqq", "wwww")
//fmt.Fprintln(res, "第一个")
//req.Header中Header本质是:type Header map[string][]string
//fmt.Fprintln(res, "Header全部数据:", header)
header := req.Header
for k1, v1 := range header {
res.Header().Set("kkk", "jjj")
res.Header().Set(k1, v1[0])
//为了让各位同学便读写代码,刻意明确给定类型
}
res.WriteHeader(200)
/*var acc []string = header["Accept"]
for _, n := range acc {
fmt.Fprintln(res, "Accepth内容:", n)
}*/
}
func main() {
server := http.Server{
Addr: "localhost:8080",
}
http.HandleFunc("/", param)
server.ListenAndServe()
}
fmt.Fprintln(res, "Header全部数据:", header)
在写入header之前写入页面就会导致head写不进云