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
+25.8k Golang : Record voice(audio) from microphone to .WAV file
+24.4k Golang : How to write CSV data to file
+9.7k Golang : Calculate Relative Strength Index(RSI) example
+12.1k Golang : Get dimension(width and height) of image file
+8.7k Golang : Function wrapper that takes arguments and return result example
+5.2k Golang : How to get capacity of a slice or array?
+3.7k Mac OSX : Get disk partitions' size, type and name
+19.2k PHP : Convert(cast) int to double/float
+18.1k Golang : Delete item from slice based on index/key position
+12k Golang : Read from buffered reader until specific number of bytes
+16.4k Golang : Read data from config file and assign to variables
+12.7k Golang : Get current time