Golang http服务

2020-03-25  本文已影响0人  懒人程序猿

开启http服务

func HttpService()  {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        // r.FormValue() 获取参数
        name := r.FormValue("name")
        id := r.FormValue("id")
        status := r.FormValue("status")
        w.Write([]byte(name + id + status + "\n"))
        w.Write([]byte(r.Host + "\n"))
        w.Write([]byte(r.RemoteAddr + "\n"))
        w.Write([]byte(r.RequestURI + "\n"))
        w.Write([]byte(r.UserAgent() + "\n"))
    })
    http.ListenAndServe("127.0.0.1:8080", nil)
}
上一篇下一篇

猜你喜欢

热点阅读