package main import ( "net/http" "net/url" "fmt" ) func main() { values := url.Values{} values.Set("username", "example_username") values.Set("password", "example_password") resp, err := http.PostForm("https://example.com/login", values) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Response:", resp) }
package main import ( "net/http" "net/url" "fmt" ) func main() { values := url.Values{} values.Set("q", "example_query") resp, err := http.PostForm("https://example.com/search", values) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Response:", resp) }In this code, we use the same process as before to encode the form data and send a POST request to the search endpoint. We can then print out the response from the server. Overall, net/http package of Go language provides a lot of features for making http requests to a server. And, PostFormValue is just one of those features that makes it really easy to send form data as part of a POST request.