页面读取不出表单,response没有数据

来源:3-9 数据协商

无谓1024

2020-05-20

func hello(w http.ResponseWriter, r *http.Request) {
	if r.URL.String() =="/" {
		fmt.Println("connection cone:", r.URL)
		body, _ := os.Open("accept/test.html")
		defer body.Close()

		w.Header().Set("Content-Type","text/html")
		w.Header().Set("Content-Encoding","gzip")
		//w.Header().Add("X-Content-Type-Options","nosniff") 不主动预测返回的数据

		//压缩
		var buf bytes.Buffer
		gw :=gzip.NewWriter(&buf)
		defer gw.Close()

		bogys ,_:=ioutil.ReadAll(body)
		gw.Write(bogys)


/*		//解压
		data :=make([]byte,1024)
		gr,_ :=gzip.NewReader(&buf)
		gr.Read(data)
		fmt.Println(string(data))
*/
		w.Write(buf.Bytes())
	}
}

func main() {
	http.HandleFunc("/", hello)
	http.ListenAndServe(":1024", nil)
}
写回答

1回答

Jokcy

2020-05-20

什么叫页面读取不出表单?

0
3
Jokcy
回复
无谓1024
亲。。。这是golang的代码吧。。。在这里问好像不太合适吧
2020-05-26
共3条回复

HTTP协议原理+实践 完整案例解析主流技术

解析HTTP协议原理 夯实HTTP技术基础 打通前后端助你快速成长

4313 学习 · 375 问题

查看课程