package main import ( "fmt" "net/http" ) func main() { resp, err := http.Get("https://example.com") if err != nil { fmt.Println("Error:", err) } defer resp.Body.Close() fmt.Println("Status:", resp.Status) fmt.Println("Content-Length:", resp.Header.Get("Content-Length")) }
package main import ( "fmt" "net/http" "net/url" "strings" ) func main() { form := url.Values{} form.Add("name", "John") form.Add("email", "[email protected]") req, err := http.NewRequest("POST", "https://example.com", strings.NewReader(form.Encode())) if err != nil { fmt.Println("Error:", err) } req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp, err := http.DefaultClient.Do(req) if err != nil { fmt.Println("Error:", err) } defer resp.Body.Close() fmt.Println("Status:", resp.Status) }This Go program sends a POST request to "https://example.com" with some form data, reads the response, and prints out the status. In both examples, the net/http package is used to create a request and send it to the server.