自动检测网站编码
go get golang.org/x/net/html
gopm get -g -v golang.org/x/net/html简单实现请求我的博客主页。并返回内容
package main
import (
    "net/http"
    "io/ioutil"
    "fmt"
)
func main() {
    res, err := http.Get("https://www.soo9s.com/")
    if err != nil {
        panic(err)
    }
    defer res.Body.Close()
    if res.StatusCode != http.StatusOK {
        fmt.Println("Error status:", res.StatusCode)
        return
    }
    content, err := ioutil.ReadAll(res.Body)
    fmt.Printf("%s\n", content)
}


Tags: None
Archives QR Code