From 9cc2e7237bd9558f9c880ac5e6c81321bfb302c6 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 28 Nov 2013 11:26:17 +0800 Subject: [PATCH] add httplib readme --- httplib/README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 httplib/README.md diff --git a/httplib/README.md b/httplib/README.md new file mode 100644 index 00000000..e5d40612 --- /dev/null +++ b/httplib/README.md @@ -0,0 +1,46 @@ +# httplib +httplib is an libs help you to curl remote url. + +# How to use? + +## GET +you can use Get to crawl data. + + import "httplib" + + str, err := httplib.Get("http://beego.me/").String() + if err != nil { + t.Fatal(err) + } + fmt.Println(str) + +## POST +POST data to remote url + + b:=httplib.Post("http://beego.me/") + b.Param("username","astaxie") + b.Param("password","123456") + str, err := b.String() + if err != nil { + t.Fatal(err) + } + fmt.Println(str) + +## set timeout +you can set timeout in request.default is 60 seconds. + +set Get timeout: + + httplib.Get("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) + +set post timeout: + + httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) + +- first param is connectTimeout. +- second param is readWriteTimeout + +## debug +if you want to debug the request info, set the debug on + + httplib.Get("").Debug(true) \ No newline at end of file