package main import( "fmt" "io/ioutil" "net/http" ) func gethtml(url string) (r *http.Response, e error){ resp,err := http.Get(url) if err != nil { fmt.Print("error") } return resp,err } func main(){ resp, _ :=gethtml("http://www.baidu.com") defer resp.Body.Close() fmt.Println(resp.StatusCode) if resp.StatusCode==http.StatusOK{ body,err :=ioutil.ReadAll(resp.Body) if err !=nil{ fmt.Println(err) } fmt.Println(string(body))
有疑问加站长微信联系(非本文作者)