Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 2.28 KB

function.md

File metadata and controls

41 lines (35 loc) · 2.28 KB

工具方法

ghttp模块也提供了独立的包函数来实现HTTP请求,这是一些快捷方法,用于短连接请求,方法如下:

func Get(url string, data ...interface{}) (*ClientResponse, error)
func Put(url string, data ...interface{}) (*ClientResponse, error)
func Post(url string, data ...interface{}) (*ClientResponse, error)
func Delete(url string, data ...interface{}) (*ClientResponse, error)
func Connect(url string, data ...interface{}) (*ClientResponse, error)
func Head(url string, data ...interface{}) (*ClientResponse, error)
func Options(url string, data ...interface{}) (*ClientResponse, error)
func Patch(url string, data ...interface{}) (*ClientResponse, error)
func Trace(url string, data ...interface{}) (*ClientResponse, error)
func DoRequest(method, url string, data ...interface{}) (*ClientResponse, error)

func GetBytes(url string, data ...interface{}) []byte
func PutBytes(url string, data ...interface{}) []byte
func PostBytes(url string, data ...interface{}) []byte
func DeleteBytes(url string, data ...interface{}) []byte
func ConnectBytes(url string, data ...interface{}) []byte
func HeadBytes(url string, data ...interface{}) []byte
func OptionsBytes(url string, data ...interface{}) []byte
func PatchBytes(url string, data ...interface{}) []byte
func TraceBytes(url string, data ...interface{}) []byte
func RequestBytes(method string, url string, data ...interface{}) []byte

func GetContent(url string, data ...interface{}) string
func PutContent(url string, data ...interface{}) string
func PostContent(url string, data ...interface{}) string
func DeleteContent(url string, data ...interface{}) string
func ConnectContent(url string, data ...interface{}) string
func HeadContent(url string, data ...interface{}) string
func OptionsContent(url string, data ...interface{}) string
func PatchContent(url string, data ...interface{}) string
func TraceContent(url string, data ...interface{}) string
func RequestContent(method string, url string, data ...interface{}) string

函数说明与Client对象的方法说明一致,一般情况下直接使用ghttp对应的HTTP包方法来实现HTTP请求即可,非常简便。当需要自定义HTTP请求的一些细节(例如超时时间、CookieHeader等)时,就得依靠自定义的Client对象来处理了。