Last active
November 6, 2015 07:51
-
-
Save ckeyer/621b2d8ee1f618ea8cbb to your computer and use it in GitHub Desktop.
Golang HTTP GEt 设置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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