package main import ( "fmt" "net/http" ) func main() { url := "https://example.com" resp, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } client := &http.Client{} response, err := client.Do(resp) if err != nil { fmt.Println("Error sending request:", err) return } defer response.Body.Close() fmt.Println("Response Status:", response.Status) }
package main import ( "bytes" "fmt" "net/http" ) func main() { url := "https://example.com" data := bytes.NewBuffer([]byte("example data")) resp, err := http.NewRequest("POST", url, data) if err != nil { fmt.Println("Error creating request:", err) return } client := &http.Client{} response, err := client.Do(resp) if err != nil { fmt.Println("Error sending request:", err) return } defer response.Body.Close() fmt.Println("Response Status:", response.Status) }This code creates a new POST request with the specified URL and request body and sends it to the server. The response received is then printed to the console. In both examples, the package library used is "net/http".