This is a creation in Article, where the information may have evolved or changed.
<strong>//Simple Direct GET request </strong>func HttpGet () {resp, err: = http. Get ("http://www.baidu.com") if err! = Nil {//Handle error} Defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil {//Handle error} FMT. Println (String)}<strong>//POST request--using HTTP. The Post () method </strong>func HttpPost () {resp, err: = http. Post ("http://www.baidu.com", "application/x-www-form-urlencoded", strings. Newreader ("NAME=CJB")) if err! = Nil {fmt. PRINTLN (ERR)} Defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil {//Handle error} FMT. Println (body)}tips: Using this method, the second parameter is set to "application/x-www-form-urlencoded", otherwise the post parameter cannot be passed. <strong>//POST request--using HTTP. Postform () method </strong>func Httppostform () {resp, err: = http. Postform ("http://www.baidu.com", url. values{"key": {"Value"}, "id": {"123"}}) if Err! = Nil {///HandlE error} Defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil {//Handle error} FMT. Println (string)}<strong>//complex requests (set header parameters, cookies, and so on) and can use HTTP. The Do () method of the client </strong>func Httpdo () {client: = &http. client{} req, err: = http. Newrequest ("POST", "http://www.baidu.com", strings. Newreader ("NAME=CJB")) if err! = Nil {///Handle error} req. Header.set ("Content-type", "application/x-www-form-urlencoded") req. Header.set ("Cookie", "Name=anny") resp, err: = client. Do (req) defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil {//Handle error} FMT. Println (String (body))}