mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-08 06:32:28 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7aa44b8a4 |
@@ -6,7 +6,8 @@
|
|||||||
// HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `url` is required.
|
// HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `url` is required.
|
||||||
// HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `params` is variable, the order is:
|
// 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[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[2] is post body which type should be []byte.
|
||||||
// params[3] is http client which type should be http.Client.
|
// params[3] is http client which type should be http.Client.
|
||||||
package netutil
|
package netutil
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ func doHttpRequest(method, reqUrl string, params ...interface{}) (*http.Response
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
|
|
||||||
err := setHeaderAndQueryAndBody(req, reqUrl, params[0], params[1], params[2])
|
err := setHeaderAndQueryAndBody(req, reqUrl, params[0], params[1], params[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -81,7 +82,12 @@ func setHeaderAndQueryAndBody(req *http.Request, reqUrl string, header, queryPar
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user