Esempio n. 1
0
func main() {
	res, err := http.Get(URI)
	if err != nil {
		panic(err)
	}

	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}

	output, err, _, _ := gogb2312.ConvertGB2312(body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(output))
}
Esempio n. 2
0
//网络请求
func httpget(url string) string {
	resp, err := http.Get(url)
	if err != nil {
		fmt.Println("httpget:", err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("httpget-ioutil.ReadAll:", err)
	}
	//bodystr := string(body)
	output, err, _, _ := gogb2312.ConvertGB2312(body) //ConvertGB2312String接收参数为string
	if err != nil {
		fmt.Println(err)
	}

	bodystr := string(output)
	return bodystr
}