import ( "net/http" "net/url" ) func main() { form := url.Values{} form.Add("username", "john.doe") form.Add("password", "12345") req, err := http.NewRequest("POST", "https://example.com/login", strings.NewReader(form.Encode())) if err != nil { // handle error } req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp, err := http.DefaultClient.Do(req) if err != nil { // handle error } // handle response }
import ( "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { // handle error } username := r.FormValue("username") password := r.FormValue("password") // process form data }In this example, a HTTP handler function is defined to extract form data from an incoming HTTP request. The form data is first parsed using the ParseForm() function, and FormValue() function is used to retrieve data from the request. The package library used in these examples is net/http, which is the standard library for making HTTP requests in Go.