func main() { http.HandleFunc("/", foo) log.Println("Listening...") http.ListenAndServe(":6001", nil)}func foo(w http.ResponseWriter, r *http.Request) { w.Header().Set("successfull", "A Go Web Server") fi := path.Join("templates/VastPlayer", "TempVide_.txt") tmpl, err := template.ParseFiles(fi) if err != nil { w.Header().Set("Error", err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) } if err := tmpl.Execute(w, ""); err != nil { w.Header().Set("Error", err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) }}如果我给出一个有效的模板,我会在标题上得到“successfull”:“A Go Web Server”,但是如果我没有给出现有的模板,我会在标题上得到 502 Bad Gateway 和 thisHTTP/1.1 502 Bad GatewayServer: nginx/1.8.0Date: Mon, 06 Jul 2015 15:19:31 GMTContent-Type: text/htmlContent-Length: 574Connection: keep-alive我想知道是否有办法发送我通过标头获得的错误,我的意思是模板/VastPlayer/TempVide_.txt:没有这样的文件或目录
1 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
发送
w.Header().Add("Status", "200")
w.Header().Add("Body", "Book Added Successfully")
收到
fmt.Println("response Status:", resp.Header.Get("Status"))
fmt.Println("response Body:", resp.Header.Get("Body"))
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报
0/150
提交
取消