一. http客户端
1. http.Client和http.NewRequest来模拟请求
package main import ( "net/http" "io/ioutil" "fmt" ) func main() { client := &http.Client{} reqest, _ := http.NewRequest("GET", "http://www.baidu.com", nil) reqest.Header.Set("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") response,_ := client.Do(reqest) if response.StatusCode == 200 { body, _ := ioutil.ReadAll(response.Body) bodystr := string(body); fmt.Println(bodystr) } }
有疑问加站长微信联系(非本文作者)