golang use custom dns http req
golang自定义host发送http请求
func TestReq(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, "http://14.215.177.39", nil)
req.Host = "www.baidu.com"
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}