一、冒充手机访问网页
package main
import (
"fmt"
"net/http"
"net/http/httputil"
)
func main() {
request, err := http.NewRequest(http.MethodGet, "http://www.baidu.com", nil)
if err != nil {
panic(err.Error())
}
request.Header.Add("User-Agent","Mozilla/5.0(iPhone;CPU iPhone OS 11_0 like Mac OS X)AppleWebKit/604.1.38(KHTML,like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
response, err := http.DefaultClient.Do(request)
if err != nil {
panic(err.Error())
}
//关闭链接
defer response.Body.Close()
// DumpResponse与DumpRequest类似,但会转储响应。
bytes, err := httputil.DumpResponse(response, true)
if err != nil {
panic(err)
}
fmt.Println(string(bytes))
}
?
|