diff --git a/httpclient/implement/response.go b/httpclient/implement/response.go index 94e1b82..05b4499 100644 --- a/httpclient/implement/response.go +++ b/httpclient/implement/response.go @@ -14,6 +14,7 @@ import ( "git.zhangdeman.cn/zhangdeman/network/httpclient/define" "git.zhangdeman.cn/zhangdeman/serialize" "github.com/tidwall/gjson" + "net/http" "strings" ) @@ -67,7 +68,11 @@ func (r *Response) fillResponseBody(reqCfg *define.Request, response *define.Res responseContentType := response.RestyResponse.Header().Get(consts.HeaderKeyContentType.String()) if responseContentType == "" { // 返回数据未说明 Content-Type - return errors.New("response content type is empty") + if response.RestyResponse.StatusCode() != http.StatusOK { + responseContentType = "application/json" + } else { + return errors.New("response content type is empty") + } } typeArr := strings.Split(strings.Split(responseContentType, ";")[0], "/") responseType := "json"