文章预览
代码如下: package main import ( "io" // "log" "net/http" ) const form = ` ` func FormServer(w http.ResponseWriter, request *http.Request) { // 设置主机头信息 w.Header().Set("Content-Type", "text/html") // 选择了请求方式 switch request.Method { // GET请求 case "GET": io.WriteString(w, form) // POST请求 case "POST": request.ParseForm() io.WriteString(w, request.Form["in"][1]) io.WriteString(w, "\n") io.WriteString(w, request.FormValue("in")) } } /* func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) { DefaultServeMux.HandleFunc(pattern, handler) } */ func main() { http.HandleFunc("/test2", FormServer) if err := http.ListenAndServe(":8088", nil); err != nil { } } 执行结果: 然后在浏览器中输入 : http://localhost:8088/test2 页面显示两个输入框 第一个输
………………………………