






















http服务.go
package main import ( "fmt" "net/http" ) func PageHandler(w http.ResponseWriter, r *http.Request) { fmt.Println(r.RequestURI) w.Write([]byte("hello world")) } func main() { http.HandleFunc("/", PageHandler) http.ListenAndServe(":8087", nil) }
http请求.go
package main import ( "fmt" "io/ioutil" "net/http" ) func main() { res, err := http.Get("http://localhost:8087") if err != nil { fmt.Println("err:", err) return } defer res.Body.Close() resBody, err := ioutil.ReadAll(res.Body) fmt.Println("client receive:" + string(resBody)) }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。