今天整理了一下golang 中http请求的常用几种方式
1、get请求
(1)http.Get
func Get(url string) (resp *Response, err error) {
return DefaultClient.Get(url)
}
get请求可以直接使用http.Get(url)方法进行请求,非常简单
例:
func httpGet() {
resp, err := http.Get("https://open.ys7.com")
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) //请求数据进行读取
if err != nil {
// handle error
}
fmt.Println(str