Golang net/http.Post() function example

package net/http

Golang net/http.Post() function usage example

 package main

 import (
 "fmt"
 "net/http"
 "net/url"
 "strings"
 )

 func main() {

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

 resp, err := http.Post("https://www.youtube.com/results?search_query=", "text/plain", strings.NewReader(urlData.Encode()))

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

 fmt.Println("Status : ", resp.Status)

 }

References :

http://golang.org/pkg/net/http/#Post

https://www.socketloop.com/tutorials/golang-post-data-with-url-values

Advertisement