urllib

package module
v1.13.17 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 18 Imported by: 14

README

urllib

golang urllib Simple HTTP Client

分支
  • master FastHttp 追求极致的性能
  • v1 net/http 拥有完善的功能
characteristic
  • simple http client
  • automatic transcoding utf-8
Install
go get github.com/dollarkillerx/urllib
Use
  • GET
	// get
	httpCode, bytes, err := urllib.Get("http://www.baidu.com").Byte()
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("HttpCode: %d \n", httpCode)
	fmt.Println(string(bytes))
  • GET & Query
	httpCode, bytes, err = urllib.Get("http://www.baidu.com").
		Queries("q","122").
		Queries("h","1213").Byte()   // 生成URL: http://www.baidu.com?q=122&h=1213
  • POST FROM
	httpCode, bytes, err = urllib.Post("http://www.baidu.com").
		Params("q","122").
		Params("h","1213").Byte()   // URL: http://www.baidu.com  表单 q=122 h=1213
  • POST JSON
	httpCode, bytes, err = urllib.Post("http://www.baidu.com").
		SetJson([]byte(`{"MSG":"121321"}`)).Byte()   
  • PUT & DELETE
	httpCode, bytes, err = urllib.Delete("http://www.baidu.com").Byte()   
	httpCode, bytes, err = urllib.Put("http://www.baidu.com").Byte()   
  • 设置代理
	httpCode, bytes, err = urllib.Post("http://www.baidu.com").HttpProxy("http://xxxx.c").Byte()
  • set timeout
	httpCode, bytes, err = urllib.Post("http://www.baidu.com").SetTimeout(3).Byte()
  • 设置重试次数
	httpCode, bytes, err = urllib.Delete("http://www.baidu.com").ByteRetry(3)
  • set Header & 返回方式Body
	body, err := urllib.Post("http://www.baidu.com").
		SetHeader("xxx", "xxx").
		SetHeader("xxx", "xxx").Body()
	defer body.Body.Close()
  • Auth
	urllib.Post("http://www.baidu.com").SetAuth("user","passwd").Body()
  • 自定义UserAgent & 随即 UserAgent
	urllib.Post("http://www.baidu.com").SetUserAgent("chrome").Body()
	urllib.Post("http://www.baidu.com").RandUserAgent().Body()
  • Set Cookie
	urllib.Post("http://www.baidu.com").SetCookie().Body()
  • 禁止自动重定向
urllib.Get("http://www.baidu.com").NoRedirect().Body()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.0.0

type Config struct {
	UserAgent       string
	ConnectTimeout  time.Duration
	TLSClientConfig *tls.Config
	Proxy           func(*http.Request) (*url.URL, error)
	Transport       http.RoundTripper
	CheckRedirect   func(req *http.Request, via []*http.Request) error
	Gzip            bool
	Debug           bool
}

type Urllib added in v1.0.0

type Urllib struct {
	// contains filtered or unexported fields
}

公开Urllib 方便未来定制包装

func Delete

func Delete(url string) *Urllib

func Get

func Get(url string) *Urllib
func Head(url string) *Urllib

func Post

func Post(url string) *Urllib

func Put

func Put(url string) *Urllib

func (*Urllib) AlloverTLS added in v1.0.0

func (u *Urllib) AlloverTLS() *Urllib

允许所有TLS

func (*Urllib) Body added in v1.0.0

func (u *Urllib) Body() (*http.Response, error)

func (*Urllib) BodyRetry added in v1.0.0

func (u *Urllib) BodyRetry(retry int) (body *http.Response, err error)

拥有重尝 版本

func (*Urllib) Byte added in v1.0.0

func (u *Urllib) Byte() (int, []byte, error)

func (*Urllib) ByteOriginal added in v1.13.11

func (u *Urllib) ByteOriginal() (int, []byte, error)

func (*Urllib) ByteOriginalRetry added in v1.13.11

func (u *Urllib) ByteOriginalRetry(retry int, code int) (statusCode int, body []byte, err error)

func (*Urllib) ByteRetry added in v1.0.0

func (u *Urllib) ByteRetry(retry int, code int) (statusCode int, body []byte, err error)

func (*Urllib) Debug added in v1.0.7

func (u *Urllib) Debug() *Urllib

func (*Urllib) DisguisedIP added in v1.13.1

func (u *Urllib) DisguisedIP(ip string) *Urllib

func (*Urllib) FromJson added in v1.13.14

func (u *Urllib) FromJson(r interface{}) error

func (*Urllib) FromJsonByCode added in v1.13.15

func (u *Urllib) FromJsonByCode(r interface{}, code int) error

func (*Urllib) KeepAlives added in v1.13.11

func (u *Urllib) KeepAlives() *Urllib

func (*Urllib) NoRedirect added in v1.0.0

func (u *Urllib) NoRedirect() *Urllib

func (*Urllib) Params added in v1.0.0

func (u *Urllib) Params(key, val string) *Urllib

func (*Urllib) ParamsMap added in v1.0.0

func (u *Urllib) ParamsMap(data map[string]string) *Urllib

func (*Urllib) PostFile added in v1.0.0

func (u *Urllib) PostFile(fromKey, filePath string) *Urllib

func (*Urllib) PreventEOF added in v1.3.0

func (u *Urllib) PreventEOF() *Urllib

防止请求服务器Socks关闭引起 EOF错误

func (*Urllib) Queries added in v1.0.0

func (u *Urllib) Queries(key, val string) *Urllib

func (*Urllib) QueriesMap added in v1.0.0

func (u *Urllib) QueriesMap(data map[string]string) *Urllib

func (*Urllib) RandDisguisedIP added in v1.13.2

func (u *Urllib) RandDisguisedIP() *Urllib

func (*Urllib) RandUserAgent added in v1.0.0

func (u *Urllib) RandUserAgent() *Urllib

func (*Urllib) SetAuth added in v1.0.0

func (u *Urllib) SetAuth(user, password string) *Urllib

func (*Urllib) SetBody added in v1.0.0

func (u *Urllib) SetBody(body []byte) *Urllib

func (*Urllib) SetCheckRedirect added in v1.0.0

func (u *Urllib) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *Urllib

func (*Urllib) SetConfig added in v1.0.0

func (u *Urllib) SetConfig(config Config) *Urllib

func (*Urllib) SetCookie added in v1.0.0

func (u *Urllib) SetCookie(cookie *http.Cookie) *Urllib

func (*Urllib) SetGzip added in v1.0.0

func (u *Urllib) SetGzip() *Urllib

func (*Urllib) SetHTTPVersion added in v1.0.0

func (u *Urllib) SetHTTPVersion(version string) *Urllib

func (*Urllib) SetHeader added in v1.0.0

func (u *Urllib) SetHeader(k, v string) *Urllib

func (*Urllib) SetHeaderMap added in v1.0.0

func (u *Urllib) SetHeaderMap(headMap map[string]string) *Urllib

func (*Urllib) SetHost added in v1.0.0

func (u *Urllib) SetHost(host string) *Urllib

func (*Urllib) SetJson added in v1.0.0

func (u *Urllib) SetJson(body []byte) *Urllib

func (*Urllib) SetJsonObject added in v1.0.0

func (u *Urllib) SetJsonObject(obj interface{}) *Urllib

func (*Urllib) SetProxy added in v1.0.0

func (u *Urllib) SetProxy(proxy func(*http.Request) (*url.URL, error)) *Urllib

func (*Urllib) SetTLSClientConfig added in v1.0.0

func (u *Urllib) SetTLSClientConfig(config *tls.Config) *Urllib

func (*Urllib) SetTimeout added in v1.0.0

func (u *Urllib) SetTimeout(timeout time.Duration) *Urllib

func (*Urllib) SetTransport added in v1.0.0

func (u *Urllib) SetTransport(transport http.RoundTripper) *Urllib

func (*Urllib) SetUserAgent added in v1.0.0

func (u *Urllib) SetUserAgent(ua string) *Urllib

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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