Answers for "how to send application/x-www-form-urlencoded request in golang"

Go
1

how to send application/x-www-form-urlencoded request in golang

// Adding key:values into application/x-www-form-urlencoded type req
form := url.Values{}
form.Add("key1", "value1")
form.Add("key2", "value2")
form.Add("key3", "value3")

// Preparing HTTP Request
req, err := http.NewRequest("POST", HOST, strings.NewReader(form.Encode()))
if err != nil {
    e.Logger.Info("Error: %v", err)
    return err
}

// Setting Content Type
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

// Sending HTTP request
respNew, err := http.DefaultClient.Do(req)
if err != nil {
  	e.Logger.Info("Error: %v", err)
	return err
}
Posted by: Guest on August-27-2021

Code answers related to "how to send application/x-www-form-urlencoded request in golang"

Browse Popular Code Answers by Language