diff --git a/netutil/http.go b/netutil/http.go index c46c8c0..cbb67a3 100644 --- a/netutil/http.go +++ b/netutil/http.go @@ -6,7 +6,8 @@ // HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `url` is required. // HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `params` is variable, the order is: // params[0] is header which type should be http.Header or map[string]string, -// params[1] is query param which type should be url.Values or map[string]interface{}, +// params[1] is query param which type should be url.Values or map[string]interface{}, when content-type header is +// multipart/form-data or application/x-www-form-urlencoded must pass url.Values params // params[2] is post body which type should be []byte. // params[3] is http client which type should be http.Client. package netutil diff --git a/netutil/net_internal.go b/netutil/net_internal.go index f796091..7ecc8ce 100644 --- a/netutil/net_internal.go +++ b/netutil/net_internal.go @@ -41,6 +41,7 @@ func doHttpRequest(method, reqUrl string, params ...interface{}) (*http.Response return nil, err } case 3: + err := setHeaderAndQueryAndBody(req, reqUrl, params[0], params[1], params[2]) if err != nil { return nil, err @@ -81,7 +82,12 @@ func setHeaderAndQueryAndBody(req *http.Request, reqUrl string, header, queryPar if err != nil { return err } - err = setBodyByte(req, body) + if req.Header.Get("Content-Type") == "multipart/form-data" || req.Header.Get("Content-Type") == "application/x-www-form-urlencoded" { + formData := queryParam.(url.Values) + err = setBodyByte(req, formData.Encode()) + } else { + err = setBodyByte(req, body) + } if err != nil { return err }