You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
574 B
29 lines
574 B
package httpclient
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
func DoHttp(url, method, body string, headers map[string]string) (string, int) {
|
|
req, err := http.NewRequest(method, url, bytes.NewBuffer([]byte(body)))
|
|
if err != nil {
|
|
return "", 0
|
|
}
|
|
for key, value := range headers {
|
|
req.Header.Set(key, value)
|
|
}
|
|
client := &http.Client{}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return "", 0
|
|
}
|
|
defer resp.Body.Close()
|
|
respBody, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return "", resp.StatusCode
|
|
}
|
|
return string(respBody), resp.StatusCode
|
|
}
|