go io/ioutil ioutil.ReadAll(res.Body) 和 http.Get()
作者:互联网
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
res, err := http.Get("https://www.baidu.com")
if err != nil {
fmt.Println("get err:", err)
return
}
data, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println("get data err:", err)
return
}
fmt.Println(string(data))
}
输出:
标签:Body,ReadAll,http,ioutil,err,res,fmt,Println 来源: https://www.cnblogs.com/heris/p/16032765.html