Skip to content

Instantly share code, notes, and snippets.

@ckeyer
Last active November 6, 2015 07:51
Show Gist options
  • Save ckeyer/621b2d8ee1f618ea8cbb to your computer and use it in GitHub Desktop.
Save ckeyer/621b2d8ee1f618ea8cbb to your computer and use it in GitHub Desktop.
Golang HTTP GEt 设置
package monitor
import (
"errors"
"net"
"net/http"
"time"
“crypto/tls"
)
// 返回Get数据
func httpGet(url string) (data []byte, err error) {
c := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
Timeout: 3 * time.Second,
}
resp, err := c.Get(url)
if err != nil {
return
}
defer resp.Body.Close()
data, err = ioutil.ReadAll(resp.Body)
if err != nil {
return
}
if resp.StatusCode != 200 {
err = errors.New("请求主机状态码为: " + string(resp.StatusCode))
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment