package main
import (
"net/http"
"io/ioutil"
"fmt"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
buf := make([]byte, 1024)
n, _ := r.Body.Read(buf)
fmt.Println(string(buf[0:n]))
// 或者
body, _ := ioutil.ReadAll(r.Body)
fmt.Println(string(body))
fmt.Fprintf(w, "Hello golang!")
})
有疑问加站长微信联系(非本文作者)