package main

import (
	"fmt"
	"net/http"
	"net/http/httputil"
)

func main() {

	request, err := http.NewRequest(http.MethodGet, "http://www.baidu.com", nil)

	request.Header.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1")

	clent := http.Client{CheckRedirect: func(req *http.Request, via []*http.Request) error {
		fmt.Println("Redirect :", req)
		return nil
	}}
	resp, err := clent.Do(request)
	//resp ,err := http.DefaultClient.Do(request)
	//resp ,err := http.Get("http://www.imooc.com")
	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()
	s, err := httputil.DumpResponse(resp, true)
	if err != nil {
		panic(err)
	}

	fmt.Printf(" %s\n", s)
}
