fix serialize

This commit is contained in:
2024-10-24 21:48:01 +08:00
parent 73999a8452
commit faef357487
4 changed files with 24 additions and 11 deletions

View File

@ -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 {