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
+7.6k Golang : Get YouTube playlist
+5.8k Unix/Linux : How to find out the hard disk size?
+11.9k How to tell if a binary(executable) file or web application is built with Golang?
+5.9k Get website traffic ranking with Similar Web or Alexa
+25.6k Golang : Convert long hexadecimal with strconv.ParseUint example
+14.6k Golang : Simple word wrap or line breaking example
+18.8k Golang : Generate thumbnails from images
+11.3k Google Maps URL parameters configuration
+13.2k Golang : Calculate elapsed years or months since a date
+10.5k Golang : Embed secret text string into binary(executable) file
+19.4k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+16.7k Golang : Execute terminal command to remote machine example