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
+10.9k Golang : Characters limiter example
+5.7k Golang : Convert Chinese UTF8 characters to Pin Yin
+5.1k PHP : Convert CSV to JSON with YQL example
+8.3k Golang : How to join strings?
+21.5k Golang : Convert seconds to minutes and remainder seconds
+27.3k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+22.5k Golang : Gorilla mux routing example
+28.3k Golang : Record voice(audio) from microphone to .WAV file
+11.4k Golang : Verify Linux user password again before executing a program example
+11.2k How to tell if a binary(executable) file or web application is built with Golang?
+8.4k Golang : Take screen shot of browser with JQuery example
+11k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions