我已经实现了以下代码,用于在Go中重试http发布请求。
在第二次重试尝试中,我总是将请求正文设为null。我试过推迟req.body.close(),但是它不起作用。谁能帮我解决这个问题?
func httpRetry(req *http.Request, timeOut time.Duration, retryAttempts int, retryDelay time.Duration) (*http.Response, error) {
attempts := 0
for {
attempts++
fmt.Println("Attempt - ", attempts)
statusCode := 0
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
var netClient = &http.Client{
Timeout: time.Second * timeOut,
Transport: tr,
}
fmt.Println("ret 88888 ", req)
response, err := netClient.Do(req)
//defer req.Body.Close()
fmt.Println(response, " dd", err)
if response != nil {
fmt.Println(response.StatusCode)
statusCode = response.StatusCode
}
if err != nil {
fmt.Println(err)
//return response, err
}
if …Run Code Online (Sandbox Code Playgroud)