go语言使用http/net包中的http请求中的Get方法
代码如下:
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
response, err := http.Get("http://www.baidu.com")
if err != nil {
fmt.Println(err)
}
body, _ := ioutil.ReadAll(response.Body) //使用ioutil读取请求体重的所有内容,并使用body进行接受.
fmt.Println(string(body))
defer response.Body.Close()
}
net/http包中的Get方法的底层也是调用Client的Get方法.