package main import ( "fmt" "net/http" ) func main() { response, err := http.Get("http://example.com") if err != nil { fmt.Println("Error:", err) return } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { fmt.Println("Error:", err) return } fmt.Println(string(body)) }
package main import ( "fmt" "net/http" "strings" ) func main() { payload := strings.NewReader("username=admin&password=password") response, err := http.Post("http://example.com/login", "application/x-www-form-urlencoded", payload) if err != nil { fmt.Println("Error:", err) return } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { fmt.Println("Error:", err) return } fmt.Println(string(body)) }In this example, we use the Post function to send a POST request to example.com/login with a payload of username=admin&password=password. We then read and print out the response body. The net/http package is part of the standard library in Go.