v1.12.10 Latest Latest

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

Go to latest
Published: Aug 22, 2020 License: Apache-2.0 Imports: 20 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.



Package httplib is used as http.Client Usage:

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 added in v1.3.0

func SetDefaultSetting(setting BeegoHTTPSettings)

SetDefaultSetting 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 added in v1.6.0

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 added in v1.5.0

func NewBeegoRequest(rawurl, method string) *BeegoHTTPRequest

NewBeegoRequest 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 added in v1.6.0

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

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

func (*BeegoHTTPRequest) Bytes added in v1.6.0

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

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

func (*BeegoHTTPRequest) Debug added in v1.6.0

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

Debug sets show debug or not when executing request.

func (*BeegoHTTPRequest) DoRequest added in v1.6.0

func (b *BeegoHTTPRequest) DoRequest() (resp *http.Response, err error)

DoRequest will do the client.Do

func (*BeegoHTTPRequest) DumpBody added in v1.6.0

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

DumpBody setting whether need to Dump the Body.

func (*BeegoHTTPRequest) DumpRequest added in v1.6.0

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

DumpRequest return the DumpRequest

func (*BeegoHTTPRequest) GetRequest added in v1.6.0

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

GetRequest return the request object

func (*BeegoHTTPRequest) Header added in v1.6.0

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

Header add header item string in request.

func (*BeegoHTTPRequest) JSONBody added in v1.6.0

func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)

JSONBody adds request raw body encoding by JSON.

func (*BeegoHTTPRequest) Param added in v1.6.0

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 added in v1.6.0

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

PostFile add a post file to the request

func (*BeegoHTTPRequest) Response added in v1.6.0

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

Response executes request client gets response mannually.

func (*BeegoHTTPRequest) Retries added in v1.8.0

func (b *BeegoHTTPRequest) Retries(times int) *BeegoHTTPRequest

Retries sets Retries times. default is 0 means no retried. -1 means retried forever. others means retried times.

func (*BeegoHTTPRequest) RetryDelay added in v1.12.3

func (b *BeegoHTTPRequest) RetryDelay(delay time.Duration) *BeegoHTTPRequest

func (*BeegoHTTPRequest) SetBasicAuth added in v1.6.0

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) SetCheckRedirect added in v1.7.2

func (b *BeegoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *BeegoHTTPRequest

SetCheckRedirect specifies the policy for handling redirects.

If CheckRedirect is nil, the Client uses its default policy, which is to stop after 10 consecutive requests.

func (*BeegoHTTPRequest) SetCookie added in v1.6.0

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

SetCookie add cookie into request.

func (*BeegoHTTPRequest) SetEnableCookie added in v1.6.0

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

SetEnableCookie sets enable/disable cookiejar

func (*BeegoHTTPRequest) SetHost added in v1.6.0

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

SetHost set the request host

func (*BeegoHTTPRequest) SetProtocolVersion added in v1.6.0

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

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

func (*BeegoHTTPRequest) SetProxy added in v1.6.0

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

SetProxy set the http proxy example:

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

func (*BeegoHTTPRequest) SetTLSClientConfig added in v1.6.0

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

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*BeegoHTTPRequest) SetTimeout added in v1.6.0

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

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

func (*BeegoHTTPRequest) SetTransport added in v1.6.0

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

SetTransport set the setting transport

func (*BeegoHTTPRequest) SetUserAgent added in v1.6.0

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

SetUserAgent sets User-Agent header field

func (*BeegoHTTPRequest) Setting added in v1.6.0

Setting Change request settings

func (*BeegoHTTPRequest) String added in v1.6.0

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

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

func (*BeegoHTTPRequest) ToFile added in v1.6.0

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

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

func (*BeegoHTTPRequest) ToJSON added in v1.6.0

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 added in v1.6.0

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.

func (*BeegoHTTPRequest) ToYAML added in v1.10.0

func (b *BeegoHTTPRequest) ToYAML(v interface{}) error

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

func (*BeegoHTTPRequest) XMLBody added in v1.9.2

func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error)

XMLBody adds request raw body encoding by XML.

func (*BeegoHTTPRequest) YAMLBody added in v1.10.0

func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error)

YAMLBody adds request raw body encoding by YAML.

type BeegoHTTPSettings added in v1.6.0

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
	CheckRedirect    func(req *http.Request, via []*http.Request) error
	EnableCookie     bool
	Gzip             bool
	DumpBody         bool
	Retries          int // if set to -1 means will retry forever
	RetryDelay       time.Duration

BeegoHTTPSettings is the http.Client setting

Jump to

Keyboard shortcuts

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