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))
}
本文介绍了一个简单的Go语言程序,该程序使用标准库中的http包从互联网上获取网页内容,并将其打印到控制台。通过本示例,读者可以了解如何发起HTTP请求并读取响应。
3122

被折叠的 条评论
为什么被折叠?



