使用 golang 自带的 net/http 包发起请求
resp, err := http.Get("http://127.0.0.1:9999/api/v1/hello-world?name=world")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
func ExampleRequest() {
http := HttpRequest{}
res, err := http.Request("GET", "https://www.baidu.com", nil).ParseBytes()
if err != nil {
panic(err)
}
fmt.Printf("%#v", res)
http := HttpRequest{}
var resp map[string]any
err := http.Request("GET", "http://127.0.0.1:9999/api/v1/hello-world?name=world", nil).ParseJson(&resp)
if err != nil {
panic(err)
}
fmt.Printf("%#v", resp)
}