GitXplorerGitXplorer
i

go-httplib

public
1 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
a76d5e263c77577abdc04decdf11ba6ac2e27499

add yaml/xml request

committed 5 years ago
Unverified
9cee383dbff2a69e959d211fe405411ae9ec5ef3

add PATCH METHOD

iicyxp committed 7 years ago
Unverified
daddb16bbde88b9f89f2fa490ec66245efca07a3

update jsonbody

iicyxp committed 8 years ago
Unverified
9d9782af06ae75a163ec68e63449d0f7b600b529

fist commit

iicyxp committed 8 years ago

README

The README file for this repository.

httplib

httplib is an libs help you to curl remote url.

How to use?

GET

you can use Get to crawl data.

import "github.com/icyxp/go-httplib"

str, err := httplib.Get("http://jiunile.com/").String()
if err != nil {
    	// error
}
fmt.Println(str)

POST

POST data to remote url

req := httplib.Post("http://jiunile.com/")
req.Param("username","jiunile")
req.Param("password","123456")
str, err := req.String()
if err != nil {
    	// error
}
fmt.Println(str)

Set timeout

The default timeout is 60 seconds, function prototype:

SetTimeout(connectTimeout, readWriteTimeout time.Duration)

Example:

// GET
httplib.Get("http://jiunile.com/").SetTimeout(100 * time.Second, 30 * time.Second)

// POST
httplib.Post("http://jiunile.com/").SetTimeout(100 * time.Second, 30 * time.Second)

Debug

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

httplib.Get("http://jiunile.com/").Debug(true)

Set HTTP Basic Auth

str, err := Get("http://jiunile.com/").SetBasicAuth("user", "passwd").String()
if err != nil {
    	// error
}
fmt.Println(str)

Set HTTPS

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 http://golang.org/pkg/crypto/tls/#Config

Set HTTP Version

some servers need to specify the protocol version of HTTP

httplib.Get("http://jiunile.com/").SetProtocolVersion("HTTP/1.1")

Set Cookie

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

cookie := &http.Cookie{}
cookie.Name = "username"
cookie.Value  = "jiunile"
httplib.Get("http://jiunile.com/").SetCookie(cookie)

Upload file

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

req := httplib.Post("http://jiunile.com/")
req.Param("username","jiunile")
req.PostFile("uploadfile1", "httplib.pdf")
str, err := req.String()
if err != nil {
    	// error
}
fmt.Println(str)

See godoc for further documentation and examples.