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
+9.3k Golang : How to get garbage collection data?
+5.2k Golang : The Tao of importing package
+8.2k Golang : Qt splash screen with delay example
+19.6k Golang : Get current URL example
+10k Golang : Read file and convert content to string
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+5.4k Golang : Display advertisement images or strings on random order
+15.9k Golang : Read a file line by line
+9.6k Golang : Validate IPv6 example
+25.7k Golang : missing Mercurial command
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+10.1k Golang : How to get quoted string into another string?