v0.0.0-...-c3255e3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2018 License: Apache-2.0, Apache-2.0 Imports: 18 Imported by: 0



httplib is an libs help you to curl remote url.

How to use?


you can use Get to crawl data.

import ""

str, err := httplib.Get("").String()
if err != nil {
    	// error


POST data to remote url

req := httplib.Post("")
str, err := req.String()
if err != nil {
    	// error

Set timeout

The default timeout is 60 seconds, function prototype:

SetTimeout(connectTimeout, readWriteTimeout time.Duration)


// GET
httplib.Get("").SetTimeout(100 * time.Second, 30 * time.Second)

httplib.Post("").SetTimeout(100 * time.Second, 30 * time.Second)


If you want to debug the request info, set the debug on


Set HTTP Basic Auth

str, err := Get("").SetBasicAuth("user", "passwd").String()
if err != nil {
    	// error


If request url is https, You can set the client support TSL:

httplib.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})

More info about the tls.Config please visit

Set HTTP Version

some servers need to specify the protocol version of HTTP


some http request need setcookie. So set it like this:

cookie := &http.Cookie{}
cookie.Name = "username"
cookie.Value  = "astaxie"

Upload file

httplib support mutil file upload, use req.PostFile()

req := httplib.Post("")
req.PostFile("uploadfile1", "httplib.pdf")
str, err := req.String()
if err != nil {
    	// error

See godoc for further documentation and examples.




import ""

	b := httplib.Post("")
	b.PostFile("uploadfile1", "httplib.pdf")
	b.PostFile("uploadfile2", "httplib.txt")
	str, err := b.String()
	if err != nil {

 more docs



This section is empty.


This section is empty.


func SetDefaultSetting

func SetDefaultSetting(setting BeegoHttpSettings)

Overwrite default settings

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.


type BeegoHttpRequest

type BeegoHttpRequest struct {
	// contains filtered or unexported fields

BeegoHttpRequest provides more useful methods for requesting one url than http.Request.

func Delete

func Delete(url string) *BeegoHttpRequest

Delete returns *BeegoHttpRequest DELETE method.

func Get

func Get(url string) *BeegoHttpRequest

Get returns *BeegoHttpRequest with GET method.

func Head(url string) *BeegoHttpRequest

Head returns *BeegoHttpRequest with HEAD method.

func NewBeegoRequest

func NewBeegoRequest(rawurl, method string) *BeegoHttpRequest

return *BeegoHttpRequest with specific method

func Post

func Post(url string) *BeegoHttpRequest

Post returns *BeegoHttpRequest with POST method.

func Put

func Put(url string) *BeegoHttpRequest

Put returns *BeegoHttpRequest with PUT method.

func (*BeegoHttpRequest) Body

func (b *BeegoHttpRequest) Body(data interface{}) *BeegoHttpRequest

Body adds request raw body. it supports string and []byte.

func (*BeegoHttpRequest) Bytes

func (b *BeegoHttpRequest) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*BeegoHttpRequest) Debug

func (b *BeegoHttpRequest) Debug(isdebug bool) *BeegoHttpRequest

Debug sets show debug or not when executing request.

func (*BeegoHttpRequest) DumpBody

func (b *BeegoHttpRequest) DumpBody(isdump bool) *BeegoHttpRequest

Dump Body.

func (*BeegoHttpRequest) DumpRequest

func (b *BeegoHttpRequest) DumpRequest() []byte

return the DumpRequest

func (*BeegoHttpRequest) GetRequest

func (b *BeegoHttpRequest) GetRequest() *http.Request

get request

func (*BeegoHttpRequest) Header

func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest

Header add header item string in request.

func (*BeegoHttpRequest) JsonBody

func (b *BeegoHttpRequest) JsonBody(obj interface{}) (*BeegoHttpRequest, error)

JsonBody adds request raw body encoding by JSON.

func (*BeegoHttpRequest) Param

func (b *BeegoHttpRequest) Param(key, value string) *BeegoHttpRequest

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*BeegoHttpRequest) PostFile

func (b *BeegoHttpRequest) PostFile(formname, filename string) *BeegoHttpRequest

func (*BeegoHttpRequest) Response

func (b *BeegoHttpRequest) Response() (*http.Response, error)

Response executes request client gets response mannually.

func (*BeegoHttpRequest) SendOut

func (b *BeegoHttpRequest) SendOut() (*http.Response, error)

func (*BeegoHttpRequest) SetBasicAuth

func (b *BeegoHttpRequest) SetBasicAuth(username, password string) *BeegoHttpRequest

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*BeegoHttpRequest) SetCookie

func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest

SetCookie add cookie into request.

func (*BeegoHttpRequest) SetEnableCookie

func (b *BeegoHttpRequest) SetEnableCookie(enable bool) *BeegoHttpRequest

SetEnableCookie sets enable/disable cookiejar

func (*BeegoHttpRequest) SetHost

func (b *BeegoHttpRequest) SetHost(host string) *BeegoHttpRequest


func (*BeegoHttpRequest) SetProtocolVersion

func (b *BeegoHttpRequest) SetProtocolVersion(vers string) *BeegoHttpRequest

Set the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*BeegoHttpRequest) SetProxy

func (b *BeegoHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHttpRequest

Set http proxy example:

func(req *http.Request) (*url.URL, error) {
	u, _ := url.ParseRequestURI("")
	return u, nil

func (*BeegoHttpRequest) SetTLSClientConfig

func (b *BeegoHttpRequest) SetTLSClientConfig(config *tls.Config) *BeegoHttpRequest

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*BeegoHttpRequest) SetTimeout

func (b *BeegoHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHttpRequest

SetTimeout sets connect time out and read-write time out for BeegoRequest.

func (*BeegoHttpRequest) SetTransport

func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpRequest

Set transport to

func (*BeegoHttpRequest) SetUserAgent

func (b *BeegoHttpRequest) SetUserAgent(useragent string) *BeegoHttpRequest

SetUserAgent sets User-Agent header field

func (*BeegoHttpRequest) Setting

Change request settings

func (*BeegoHttpRequest) String

func (b *BeegoHttpRequest) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*BeegoHttpRequest) ToFile

func (b *BeegoHttpRequest) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*BeegoHttpRequest) ToJson

func (b *BeegoHttpRequest) ToJson(v interface{}) error

ToJson returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*BeegoHttpRequest) ToXml

func (b *BeegoHttpRequest) ToXml(v interface{}) error

ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type BeegoHttpSettings

type BeegoHttpSettings struct {
	ShowDebug        bool
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	TlsClientConfig  *tls.Config
	Proxy            func(*http.Request) (*url.URL, error)
	Transport        http.RoundTripper
	EnableCookie     bool
	Gzip             bool
	DumpBody         bool


Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL