|
|
@ -7,6 +7,7 @@ import ( |
|
|
|
"bytes" |
|
|
|
"crypto/md5" |
|
|
|
"encoding/hex" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"io/ioutil" |
|
|
|
"net" |
|
|
@ -49,7 +50,7 @@ func FnPost(url, param string) ([]byte, error) { |
|
|
|
/** |
|
|
|
* post 请求 |
|
|
|
*/ |
|
|
|
func PostJson(url string, param []byte) ([]byte, error) { |
|
|
|
func PostJson(url string, param []byte, header ...map[string]string) ([]byte, error) { |
|
|
|
httpClient := &http.Client{} |
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(param)) |
|
|
@ -59,6 +60,50 @@ func PostJson(url string, param []byte) ([]byte, error) { |
|
|
|
|
|
|
|
req.Header.Set("Content-Type", "application/json") |
|
|
|
|
|
|
|
if len(header) > 0 { |
|
|
|
for _, item := range header { |
|
|
|
for k, v := range item { |
|
|
|
req.Header.Set(k, v) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
resp, err := httpClient.Do(req) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|
} |
|
|
|
|
|
|
|
defer resp.Body.Close() |
|
|
|
body, err := ioutil.ReadAll(resp.Body) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|
} |
|
|
|
|
|
|
|
return body, nil |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* post 请求 |
|
|
|
*/ |
|
|
|
func PostJsonData(url string, param interface{}, header ...map[string]string) ([]byte, error) { |
|
|
|
httpClient := &http.Client{} |
|
|
|
params, err := json.Marshal(param) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|
} |
|
|
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(params)) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|
} |
|
|
|
|
|
|
|
req.Header.Set("Content-Type", "application/json") |
|
|
|
|
|
|
|
if len(header) > 0 { |
|
|
|
for _, item := range header { |
|
|
|
for k, v := range item { |
|
|
|
req.Header.Set(k, v) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
resp, err := httpClient.Do(req) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|