diff --git a/sdk/utils/httputils/request.go b/sdk/utils/httputils/request.go index c2531d69ac08050026b3eb1652ed96a0327c125c..81d5589fd8a9cd5d0ec1de47581faabd03b83acf 100644 --- a/sdk/utils/httputils/request.go +++ b/sdk/utils/httputils/request.go @@ -6,30 +6,9 @@ import ( "fmt" "io" "net/http" + "strings" ) -// Deprecated: use other api. TODO: will remove this -func Request(method, url string) ([]byte, error) { - req, err := http.NewRequest(method, url, nil) - if err != nil { - return nil, err - } - - hc := &http.Client{} - resp, err := hc.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - bs, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - return bs, nil -} - func request(method, url string, param *Params) (*Response, error) { // 处理form参数 if param != nil && len(param.Form) > 0 { @@ -60,6 +39,18 @@ func request(method, url string, param *Params) (*Response, error) { for k, v := range param.Header { req.Header.Add(k, v) } + + // 如果存在body数据,则自动加入到Content-Type信息当中 + if param.Body != nil { + typeStr := req.Header.Get("Content-Type") + if typeStr == "" { + req.Header.Set("Content-Type", "application/json") + } else { + if !strings.Contains(typeStr, "application/json") { + req.Header.Set("Content-Type", typeStr+"; application/json") + } + } + } } hc := &http.Client{}