golang用get方式读取指定网页内容

来源:互联网 发布:c 程序员网站 编辑:程序博客网 时间:2024/05/22 08:13

package main
import (
“fmt”
“io/ioutil”
“net/http”
)

func main() {
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(body))

}