github.com/astaxie/beego@v1.12.3/httplib/README.md (about) 1 # httplib 2 httplib is an libs help you to curl remote url. 3 4 # How to use? 5 6 ## GET 7 you can use Get to crawl data. 8 9 import "github.com/astaxie/beego/httplib" 10 11 str, err := httplib.Get("http://beego.me/").String() 12 if err != nil { 13 // error 14 } 15 fmt.Println(str) 16 17 ## POST 18 POST data to remote url 19 20 req := httplib.Post("http://beego.me/") 21 req.Param("username","astaxie") 22 req.Param("password","123456") 23 str, err := req.String() 24 if err != nil { 25 // error 26 } 27 fmt.Println(str) 28 29 ## Set timeout 30 31 The default timeout is `60` seconds, function prototype: 32 33 SetTimeout(connectTimeout, readWriteTimeout time.Duration) 34 35 Example: 36 37 // GET 38 httplib.Get("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) 39 40 // POST 41 httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) 42 43 44 ## Debug 45 46 If you want to debug the request info, set the debug on 47 48 httplib.Get("http://beego.me/").Debug(true) 49 50 ## Set HTTP Basic Auth 51 52 str, err := Get("http://beego.me/").SetBasicAuth("user", "passwd").String() 53 if err != nil { 54 // error 55 } 56 fmt.Println(str) 57 58 ## Set HTTPS 59 60 If request url is https, You can set the client support TSL: 61 62 httplib.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) 63 64 More info about the `tls.Config` please visit http://golang.org/pkg/crypto/tls/#Config 65 66 ## Set HTTP Version 67 68 some servers need to specify the protocol version of HTTP 69 70 httplib.Get("http://beego.me/").SetProtocolVersion("HTTP/1.1") 71 72 ## Set Cookie 73 74 some http request need setcookie. So set it like this: 75 76 cookie := &http.Cookie{} 77 cookie.Name = "username" 78 cookie.Value = "astaxie" 79 httplib.Get("http://beego.me/").SetCookie(cookie) 80 81 ## Upload file 82 83 httplib support mutil file upload, use `req.PostFile()` 84 85 req := httplib.Post("http://beego.me/") 86 req.Param("username","astaxie") 87 req.PostFile("uploadfile1", "httplib.pdf") 88 str, err := req.String() 89 if err != nil { 90 // error 91 } 92 fmt.Println(str) 93 94 95 See godoc for further documentation and examples. 96 97 * [godoc.org/github.com/astaxie/beego/httplib](https://godoc.org/github.com/astaxie/beego/httplib)