This is a creation in Article, where the information may have evolved or changed.
Package MainImport ( "FMT" "Io/ioutil" "net/http" "OS" "Strings") func GET () {client:= &http. client{} reqest, err:= http. Newrequest ("GET","http://www.baidu.com/", nil)//Create a requestifErr! =Nil {fmt. Println ("Fatal Error", Err. Error ()) OS. Exit (0)}//ADD Header Protocol reqest. Header.add ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") reqest. Header.add ("Accept-language","ja,zh-cn;q=0.8,zh;q=0.6") reqest. Header.add ("Connection","keep-alive") reqest. Header.add ("Cookies","Set Cookies") reqest. Header.add ("user-agent","mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) gecko/20100101 firefox/12.0") Response, err:= client. Do (reqest)//Submit defer response. Body.close () Cookies:= Response. Cookies ()//Traverse Cookies for_, Cookie: =Range Cookies {fmt. Println ("Cookies:", Cookies)} Body, ERR1:=Ioutil. ReadAll (response. Body)ifErr1! =Nil {//handle Error} FMT. Println (String (body))//Web Source}func post () {client:= &http. client{} req, err:= http. Newrequest ("POST","http://xxxxx", strings. Newreader ("name=1&age=2")) ifErr! =Nil {//handle Error} reqest. Header.add ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") reqest. Header.add ("Accept-language","ja,zh-cn;q=0.8,zh;q=0.6") reqest. Header.add ("Connection","keep-alive") reqest. Header.add ("Cookies","Set Cookies") reqest. Header.add ("user-agent","mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) gecko/20100101 firefox/12.0") RESP, err:=client. Do (req) Cookies:=resp. Cookies () for_, Cookie: =Range Cookies {fmt. Println ("Cookies:", Cookies)} Defer resp. Body.close () _, ERR1:=Ioutil. ReadAll (resp. Body)ifErr1! =Nil {//handle Error} FMT. Println (String (body))}func main () {GET ()}