course/HTTP/http_client_get.go

23 lines
339 B
Go

package main
import (
"fmt"
"io"
"net/http"
)
//http client
func main() {
resp, err := http.Get("http://127.0.0.1:9090/query?name=sb&age=12") //没办法自定义请求参数和client
if err != nil {
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return
}
fmt.Println(string(body))
}