【GOLANG】Go语言学习-HTTP

前端之家收集整理的这篇文章主要介绍了【GOLANG】Go语言学习-HTTP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一. http客户端

1. http.Client和http.NewRequest来模拟请求
package main
 
import (
    "net/http"
    "io/IoUtil"
    "fmt"
)
 
func main() {
    client := &http.Client{}
    reqest,_ := http.NewRequest("GET","http://www.baidu.com",nil)
     
    reqest.Header.Set("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
   
    response,_ := client.Do(reqest)
    if response.StatusCode == 200 {
        body,_ := IoUtil.ReadAll(response.Body)
        bodystr := string(body);
        fmt.Println(bodystr)
    }
}


配置Gocode ~ cd $GOPATH/src/github.com/nsf/gocode/vim ~ ./update.bash ~ gocode set propose-builtins true propose-builtins true ~ gocode set lib-path "/home/border/gocode/pkg/linux_amd64" 24lib-path "/home/border/gocode/pkg/linux_amd64" ~ gocode set
原文链接:https://www.f2er.com/go/190362.html

猜你在找的Go相关文章