Golang net/http.Client.PostForm() function example

package net/http

Golang net/http.Client.PostForm() function usage example

 package main

 import (
 "fmt"
 "io/ioutil"
 "net/http"
 "net/url"
 "os"
 )

 func main() {

 urlData := url.Values{}
 urlData.Set("search_query", "macross")

 client := &http.Client{}

 resp, err := client.PostForm("https://www.youtube.com/results?search_query=", urlData)

 if err != nil {
 panic(nil)
 }

 defer resp.Body.Close()

 htmlData, err := ioutil.ReadAll(resp.Body)

 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }

 fmt.Println(os.Stdout, string(htmlData))

 }

Reference :

http://golang.org/pkg/net/http/#Client.PostForm

Advertisement