go 网络请求篇二
Posted lpwlpw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go 网络请求篇二相关的知识,希望对你有一定的参考价值。
框架地址:https://github.com/parnurzeal/gorequest
package main //https://antarx.com/2018/05/05/gorequest-doc/ import ( "github.com/parnurzeal/gorequest" "github.com/golang/go/src/pkg/fmt" "time" "net/http" ) func main() { do_get_test() do_post_test() } func do_post_test() { url := "http://api.budejie.com/api/api_open.php" var data map[string]string /*创建集合 */ data = make(map[string]string) data["a"] = "list" data["appname"] = "baisibudejie_hd" data["asid"] = "C1180CB8-F460-4385-A77C-97CD1AA83DFD" data["c"] = "data" data["client"] = "ipad" data["device"] = "ios" data["from"] = "ios" data["jbk"] = "0" data["mac"] = "02:00:00:00:00:00" data["openudid"] = "78336166d6a434b4cf1634410eb3b692d6d3a4ee" data["order"] = "ctime" data["page"] = "1" data["per"] = "20" data["systemversion"] = "7.1" data["type"] = "10" data["ver"] = "2.0.3" data["market"] = "" data["maxtime"] = "" request := gorequest.New() resp, body, errs := request.Post(url). Set("contentType","application/x-www-form-urlencoded"). Send(data). End() if errs!=nil { fmt.Println(errs) } fmt.Println("body",body) fmt.Println("resp",resp) } func do_get_test() { url:="https://www.jianshu.com/p/419285187253" request := gorequest.New() resp, body, errs := request.Get(url). Timeout(2*time.Second). Retry(3, 5 * time.Second, http.StatusBadRequest, http.StatusInternalServerError). End(printStatus) if errs!=nil { fmt.Println(errs) } fmt.Println("body",body) fmt.Println("resp",resp) } func printStatus(resp gorequest.Response, body string, errs []error){ fmt.Println("status=======",resp.Status) }
以上是关于go 网络请求篇二的主要内容,如果未能解决你的问题,请参考以下文章
VSCode自定义代码片段14——Vue的axios网络请求封装