Go语言 之HTTP客户端
package main import ( "fmt" "io" "net/http" ) func main() { //发送get请求 resp, err := http.Get("http://www.baidu.com") if err != nil { fmt.Println(err.Error()) } defer resp.Body.Close() //响应状态 fmt.Println(resp.Status) fmt.Println(resp.Header) //获取响应内容 c := make([]byte, 2048) var result string for { n, err := resp.Body.Read(c) if err != nil && io.EOF == err { break } result += string(c[:n]) } fmt.Println("result=" + result) }