- fix retry bug (request can not be reused).

This commit is contained in:
gazebo
2018-08-15 22:06:57 +08:00
parent fa83668d82
commit 47e1b3989d
11 changed files with 65 additions and 40 deletions

View File

@@ -2,7 +2,6 @@ package weixinapi
import (
"net/http"
"strings"
"sync"
"git.rosy.net.cn/baseapi/platformapi"
@@ -91,14 +90,17 @@ func (a *API) AccessAPI(action string, params map[string]interface{}, body strin
}
fullURL := utils.GenerateGetURL(prodURL, action, params2)
// baseapi.SugarLogger.Debug(fullURL)
var request *http.Request
// var request *http.Request
var method string
if body == "" {
request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
method = http.MethodGet
// request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
} else {
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(body))
method = http.MethodPost
// request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(body))
}
request.Close = true // todo try to fix EOF error when accessing weixin api.
err = platformapi.AccessPlatformAPIWithRetry(a.client, request, a.config, func(response *http.Response) (result string, err error) {
// request.Close = true // todo try to fix EOF error when accessing weixin api.
err = platformapi.AccessPlatformAPIWithRetry(a.client, method, fullURL, body, nil, a.config, func(response *http.Response) (result string, err error) {
jsonResult1, err := utils.HTTPResponse2Json(response)
if err != nil {
return platformapi.ErrLevelGeneralFail, platformapi.ErrResponseDataFormatWrong