50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package internal
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
defaultContentType string = "text/xml; charset=UTF-8"
|
|
defaultAgent string = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; XFire Client +http://xfire.codehaus.org)"
|
|
)
|
|
|
|
//Post xml string to url
|
|
func post(url string, contentType string, msg string) (*http.Response, error) {
|
|
return http.Post(url, contentType, bytes.NewBuffer([]byte(msg)))
|
|
}
|
|
|
|
func postSim(url string, msg string) string {
|
|
timeout := time.Duration(10 * time.Second)
|
|
client := http.Client{
|
|
Timeout: timeout,
|
|
}
|
|
|
|
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(msg))
|
|
if err != nil {
|
|
return err.Error()
|
|
}
|
|
req.Header.Set("Content-Type", defaultContentType)
|
|
req.Header.Set("User-Agent", defaultAgent)
|
|
req.Header.Set("SOAPAction", "")
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return err.Error()
|
|
}
|
|
defer resp.Body.Close()
|
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return err.Error()
|
|
}
|
|
return string(respBytes)
|
|
}
|
|
|
|
//Send message
|
|
func Send(url string, message string) string {
|
|
return postSim(url, message)
|
|
}
|