Query URL without redirect in Go

后端 未结 2 1309
轻奢々
轻奢々 2020-12-17 20:23

I am writing a benchmark test for a redirect script.

I wisg my program to query certain URL that redirects to AppStore. But I do not wish to download AppStore page.

2条回答
  •  心在旅途
    2020-12-17 20:53

    You need to use an http.Transport instead of an http.Client. Transport is lower-level and does not follow redirects.

    req, err := http.NewRequest("GET", "http://example.com/redirectToAppStore", nil)
    // ...
    resp, err := http.DefaultTransport.RoundTrip(req)
    

提交回复
热议问题