Golang : Post data with url.Values{}
Just a short example on how to use url.Values{}. This code fragment is taken from previous tutorial on how to store cookies into cookie Jar.
Here you go :
urlData := url.Values{}
urlData.Set("search_query", "macross")
req, _ := http.NewRequest("POST", "https://www.youtube.com/results?search_query=", strings.NewReader(urlData.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
if err != nil {
panic(nil)
}
body, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
// display content to screen ... save this to a HTML file and view the file with browser ;-)
fmt.Println(string(body))
Happy coding!
See also : Golang : Storing cookies in http.CookieJar example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+3.9k JavaScript: Add marker function on Google Map
+5.5k Apt-get to install and uninstall Golang
+5k Unix/Linux : Get reboot history or check when was the last reboot date
+7.3k Golang : Get final or effective URL with Request.URL example
+15.2k Golang : Delete files by extension
+11.5k Golang : Validate email address
+4.4k Python : Create Whois client or function example
+8.1k Golang : Handle sub domain with Gin
+15.4k Golang : Test floating point numbers not-a-number and infinite example
+12.4k Golang : Date and Time formatting
+15.9k Golang : Get own process identifier