fix serialize
This commit is contained in:
7
resty.go
7
resty.go
@ -10,6 +10,7 @@ package httpclient
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.zhangdeman.cn/gateway/httpclient/define"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/tidwall/gjson"
|
||||
@ -67,12 +68,12 @@ func setRestyBody(reqConfig *define.Request, request *resty.Request) {
|
||||
if nil == reqConfig.Body || len(reqConfig.Body) == 0 {
|
||||
return
|
||||
}
|
||||
if strings.Contains(strings.ToLower(reqConfig.ContentType), "application/json") {
|
||||
if strings.Contains(strings.ToLower(reqConfig.ContentType), consts.MimeTypeJson) {
|
||||
request.SetBody(reqConfig.Body)
|
||||
return
|
||||
}
|
||||
if strings.Contains(strings.ToLower(reqConfig.ContentType), "application/x-www-form-urlencodeds") {
|
||||
bodyStr := serialize.JSON.MarshalForString(reqConfig.Body)
|
||||
if strings.Contains(strings.ToLower(reqConfig.ContentType), consts.MimeTypeXWWWFormUrlencoded) {
|
||||
bodyStr := serialize.JSON.MarshalForStringIgnoreError(reqConfig.Body)
|
||||
bodyData := map[string]string{}
|
||||
jsonObj := gjson.Parse(bodyStr)
|
||||
jsonObj.ForEach(func(key, value gjson.Result) bool {
|
||||
|
||||
Reference in New Issue
Block a user