We can customize the body of the request in the HTTP request sent. Here is some sample code

package main import ( "fmt" "io/ioutil" "net/http" "net/url" ) func printBody(r *http.Response){ content, err := ioutil.ReadAll(r.Body) if err ! = nil {panic(err)} fmt.printf ("%s", content)} func requestByParams(){request, err := http.NewRequest(http.MethodGet, "http://httpbin.org/get", nil) if err ! = nil { panic(err) } params := make(url.Values) params.Add("name", "yuan") params.Add("age", "18") request.URL.RawQuery = params.Encode() fmt.Println(params.Encode()) resp, err := http.DefaultClient.Do(request) if err ! = nil { panic(err) } defer func() {_ = resp.Body.Close()}() printBody(resp) //{ // "args": { // "age": "18", // "name": "yuan" //}, // "headers": { // "Accept-Encoding": "gzip", // "Host": "httpbin.org", // "User-Agent": // "X-amzn-trace-id ": "Root=1-60e46b98-58667aee5367f1aa1ca102c9" //}, //" ORIGIN ": "222.211.214.252," / / "url" : "http://httpbin.org/get?age=18&name=yuan" //}} // Customise request header func ReauestByHead (){request, err := http.NewRequest(http.MethodGet, "http://httpbin.org/get", nil) if err ! = nil { panic(err) } request.Header.Add("user-agent", "chrome") resp, err := http.DefaultClient.Do(request) if err ! = nil { panic(err) } defer func() {_ = resp.Body.Close()}() printBody(resp) //{ // "args": {}, // "headers": { // "Accept-Encoding": "gzip", // "Host": "httpbin.org", // "User-Agent": "chrome", // "X-Amzn-Trace-Id": "Root=1-60e46c63-22fd52047229e6175f52166c" //}, // "origin": "222.211.214.252", // "url": "http://httpbin.org/get" //} } func main() { requestByParams() reauestByHead() }