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)
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM