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.1k CodeIgniter : Load different view for mobile devices
+9.7k Golang : Quadratic example
+19.4k Golang : Display list of time zones with GMT
+9k Golang : Gaussian blur on image and camera video feed examples
+4.8k Linux : sudo yum updates not working
+8.8k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+22k Golang : Convert string slice to struct and access with reflect example
+7.6k Golang : Rot13 and Rot5 algorithms example
+8.6k Golang : How to check variable or object type during runtime?
+9.1k Golang : Get SPF and DMARC from email headers to fight spam
+5.1k Google : Block or disable caching of your website content
+9.1k Golang : Inject/embed Javascript before sending out to browser example