- 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

@@ -1,7 +1,6 @@
package dadaapi
import (
"bytes"
"crypto/md5"
"fmt"
"net/http"
@@ -108,10 +107,11 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
}
params2[signKey] = a.signParams(params2)
params2Bytes := utils.MustMarshal(params2)
request, _ := http.NewRequest("POST", a.url+"/"+action, bytes.NewReader(params2Bytes))
request.Header.Set("Content-Type", "application/json")
// request, _ := http.NewRequest(http.MethodPost, a.url+"/"+action, bytes.NewReader(params2Bytes))
header := make(http.Header)
header.Set("Content-Type", "application/json")
err = platformapi.AccessPlatformAPIWithRetry(a.client, request, a.config, func(response *http.Response) (result string, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client, http.MethodPost, a.url+"/"+action, string(params2Bytes), header, a.config, func(response *http.Response) (result string, err error) {
jsonResult1, err := utils.HTTPResponse2Json(response)
if err != nil {
return platformapi.ErrLevelGeneralFail, err

View File

@@ -1,6 +1,7 @@
package dadaapi
import (
"net/http"
"testing"
"git.rosy.net.cn/baseapi"
@@ -161,7 +162,7 @@ func TestCallbackMsgPlayback(t *testing.T) {
},
}
for _, v := range playbackData {
_, err := utils.SendFakeRequest("POST", v[1], v[0], "application/json; charset=utf-8")
_, err := utils.SendFakeRequest(http.MethodPost, v[1], v[0], "application/json; charset=utf-8")
if err != nil {
t.Fatal(err)
}