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
+8.7k Golang : Inject/embed Javascript before sending out to browser example
+7.2k Golang : Gorrila set route name and get the current route name
+5.8k Golang : Experimenting with the Rejang script
+4.7k Unix/Linux : secure copying between servers with SCP command examples
+37.4k Golang : Comparing date or timestamp
+29k Golang : Save map/struct to JSON or XML file
+14.1k Golang : How to filter a map's elements for faster lookup
+7.2k Golang : Convert source code to assembly language
+19.7k Golang : Convert seconds to human readable time format example
+18.4k Golang : convert int to string
+6.3k Golang : Spell checking with ispell example
+10.8k Golang : Calculate Relative Strength Index(RSI) example