course/HTTP/http_client_get.go

23 lines
339 B
Go
Raw Normal View History

2024-07-14 11:08:04 +08:00
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))
}