add http post error

This commit is contained in:
zhiqiang feng
2020-09-18 17:21:00 +08:00
parent 6f03971b6c
commit 2094ab42f7
2 changed files with 20 additions and 10 deletions
+6 -6
View File
@@ -18,7 +18,7 @@ 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 {
func postSim(url string, msg string) (string, error) {
timeout := time.Duration(10 * time.Second)
client := http.Client{
Timeout: timeout,
@@ -26,24 +26,24 @@ func postSim(url string, msg string) string {
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(msg))
if err != nil {
return err.Error()
return err.Error(), err
}
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()
return err.Error(), err
}
defer resp.Body.Close()
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err.Error()
return err.Error(), err
}
return string(respBytes)
return string(respBytes), nil
}
//Send message
func Send(url string, message string) string {
func Send(url string, message string) (string, error) {
return postSim(url, message)
}