go http 请求参数获取

//获取url parames
request.ParseForm()
values := request.Form["firs"][0]

//获取头部参数
request.Header.Get("name")


//解决post body 第二次读为空问题

func handleIterceptor(h http.HandlerFunc) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        fmt.Println("handleIterceptor")
        buff, _ := ioutil.ReadAll(r.Body)
        r.Body.Close()//必须关闭后在给body 赋值
        r.Body = ioutil.NopCloser(bytes.NewBuffer(buff))
        fmt.Println(string(buff))
        fmt.Printf("interceptor header %s\n",r.Header.Get("name"))
        h(w, r)
    }
}

 

posted @ 2020-03-12 23:46  ForMeDream  阅读(3557)  评论(0编辑  收藏  举报