1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-19 15:40:39 +00:00
Files
cache
config
context
example
httplib
README.md
httplib.go
httplib_test.go
logs
middleware
orm
session
testing
toolbox
validation
.gitignore
README.md
admin.go
app.go
beego.go
config.go
controller.go
filter.go
fiter_test.go
flash.go
log.go
reload.go
router.go
router_test.go
safemap.go
safemap_test.go
template.go
template_test.go
utils.go
utils_test.go
Beego/httplib

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)