add httplib readme
Showing
1 changed file
with
46 additions
and
0 deletions
httplib/README.md
0 → 100644
| 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 "httplib" | ||
| 10 | |||
| 11 | str, err := httplib.Get("http://beego.me/").String() | ||
| 12 | if err != nil { | ||
| 13 | t.Fatal(err) | ||
| 14 | } | ||
| 15 | fmt.Println(str) | ||
| 16 | |||
| 17 | ## POST | ||
| 18 | POST data to remote url | ||
| 19 | |||
| 20 | b:=httplib.Post("http://beego.me/") | ||
| 21 | b.Param("username","astaxie") | ||
| 22 | b.Param("password","123456") | ||
| 23 | str, err := b.String() | ||
| 24 | if err != nil { | ||
| 25 | t.Fatal(err) | ||
| 26 | } | ||
| 27 | fmt.Println(str) | ||
| 28 | |||
| 29 | ## set timeout | ||
| 30 | you can set timeout in request.default is 60 seconds. | ||
| 31 | |||
| 32 | set Get timeout: | ||
| 33 | |||
| 34 | httplib.Get("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) | ||
| 35 | |||
| 36 | set post timeout: | ||
| 37 | |||
| 38 | httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second) | ||
| 39 | |||
| 40 | - first param is connectTimeout. | ||
| 41 | - second param is readWriteTimeout | ||
| 42 | |||
| 43 | ## debug | ||
| 44 | if you want to debug the request info, set the debug on | ||
| 45 | |||
| 46 | httplib.Get("").Debug(true) | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment