go语言接收http请求

func sayHello(w http.ResponseWriter, r *http.Request) {
    r.ParseForm()//获取请求参数
    fmt.Fprintf(w, "hello world")//返回前台页面

}
func saystu(w http.ResponseWriter, r *http.Request) {
    r.ParseForm()
    fmt.Fprintf(w, "hello student")
}

func main() {
    fmt.Print("com in")
    http.HandleFunc("/test", sayHello)
    http.HandleFunc("/test2", saystu)
    err := http.ListenAndServe(":80", nil)
    if err != nil {
        log.Fatal("ListenAndServe", err)
    }
}

访问:http://localhost/test2

posted @ 2019-07-02 11:15  口水青春  阅读(2362)  评论(0编辑  收藏  举报