[實作] 從零開始用 Golang 寫網頁 : 02 獲得 http 請求參數
取得 http 請求的內容,這些內容保存在 http.Request 中,也就是上一篇中 myWeb 函式中的參數 r
1  | func myWeb(w http.ResponseWriter, r *http.Request) {  | 
myWeb
使用
r.ParseForm(),將數據填充到r.Form和r.PostForm接著循環打印出
r.URL.Query()函式返回的值和r.PostForm值裡的每一個參數
結果
- 用終端機使用 curl 指令 Post 網站
 
1  | curl --request POST --url "http://localhost:8080/?name=kenny" --header "cache-control: no-cache" --header "content-type: application/x-www-form-urlencoded" --data description=hello  | 
- 就會打印出 http 請求參數
 
1  | key : name , value : kenny  | 
