resp, err := http.Get("https://example.com") if err != nil { // handle error } defer resp.Body.Close() fmt.Println(resp.StatusCode)
resp, err := http.Post("https://example.com", "text/plain", bytes.NewBufferString("Hello, world!")) if err != nil { // handle error } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { // handle error } fmt.Println(string(body))This example sends an HTTP POST request to "https://example.com" with a text/plain content type and a request body of "Hello, world!". It then reads the response body into a byte slice and prints it as a string. Both of these examples use the net/http package in Go.