//下载插件工具
go get -v github.com/gpmgo/gopm
//自动导入包插件
gopm get -g -v golang.org/x/tools/cmd/goimports
//转码插件
gopm get -g -v golang.org/x/text
package main
import (
"net/http"
"io/ioutil"
"fmt"
"golang.org/x/text/transform"
"golang.org/x/text/encoding/simplifiedchinese"
)
func main() {
resp, err := http.Get("http://www.zhenai.com/zhenghun")
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Println("Error:status code", resp.StatusCode)
return
}
utf8Reader:=transform.NewReader(resp.Body,simplifiedchinese.GBK.NewDecoder())
all, err := ioutil.ReadAll(utf8Reader)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", all)
}