zoukankan      html  css  js  c++  java
  • 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) }
  • 相关阅读:
    p 继承
    linux
    python 类的特性
    python 类的继承
    python 类
    pyhon对象初始
    coding++:win10家庭版升级专业版方案
    coding++:Java 获取request中的参数
    coding++:高并发解决方案限流技术--计数器--demo
    coding++:高并发解决方案限流技术---漏桶算法限流--demo
  • 原文地址:https://www.cnblogs.com/lpwlpw/p/10051946.html
Copyright © 2011-2022 走看看