|
|
@ -84,3 +84,43 @@ func SendHttp(method, url string, param map[string]string, header ...map[string] |
|
|
|
|
|
|
|
return body, nil |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* send xml |
|
|
|
*/ |
|
|
|
func SendXml(method, url string, requestxml interface{}, header ...map[string]string) ([]byte, error) { |
|
|
|
|
|
|
|
bytexml, err := xml.Marshal(&requestxml) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|
} |
|
|
|
|
|
|
|
httpClient := &http.Client{} |
|
|
|
|
|
|
|
req, err := http.NewRequest(method, url, bytes.NewBuffer(param)) |
|
|
|
if err != nil { |
|
|
|
return []byte(""), err |
|
|
|
} |
|
|
|
|
|
|
|
req.Header.Add("Content-Type", "application/xml; charset=utf-8") |
|
|
|
|
|
|
|
if len(header) > 0 { |
|
|
|
for _, item := range header { |
|
|
|
for k, v := range item { |
|
|
|
req.Header.Add(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 |
|
|
|
} |