This commit is contained in:
laodaming
2023-08-09 19:34:11 +08:00
parent 583592b7d3
commit 5470f22e77
3 changed files with 82 additions and 24 deletions

View File

@@ -1,15 +1,15 @@
package curl
import (
"bytes"
"errors"
"io"
"net/http"
"strings"
"time"
)
// 接口请求
func ApiCall(url, method string, header map[string]string, postData []byte, timeOut time.Duration) (rsp *http.Response, err error) {
func ApiCall(url, method string, header map[string]string, body io.Reader, timeOut time.Duration) (rsp *http.Response, err error) {
method = strings.ToUpper(method)
if method != "GET" && method != "POST" && method != "PUT" && method != "DELETE" {
return nil, errors.New("invalid http method")
@@ -23,7 +23,7 @@ func ApiCall(url, method string, header map[string]string, postData []byte, time
} else {
client.Timeout = timeOut
}
requestHandle, err := http.NewRequest(method, url, bytes.NewReader(postData))
requestHandle, err := http.NewRequest(method, url, body)
if err != nil {
return nil, err
}