github.com/zhongdalu/gf@v1.0.0/g/net/ghttp/ghttp_client_api.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 // HTTP客户端请求. 8 9 package ghttp 10 11 func Get(url string) (*ClientResponse, error) { 12 return DoRequest("GET", url) 13 } 14 15 func Put(url string, data ...interface{}) (*ClientResponse, error) { 16 return DoRequest("PUT", url, data...) 17 } 18 19 func Post(url string, data ...interface{}) (*ClientResponse, error) { 20 return DoRequest("POST", url, data...) 21 } 22 23 func Delete(url string, data ...interface{}) (*ClientResponse, error) { 24 return DoRequest("DELETE", url, data...) 25 } 26 27 func Head(url string, data ...interface{}) (*ClientResponse, error) { 28 return DoRequest("HEAD", url, data...) 29 } 30 31 func Patch(url string, data ...interface{}) (*ClientResponse, error) { 32 return DoRequest("PATCH", url, data...) 33 } 34 35 func Connect(url string, data ...interface{}) (*ClientResponse, error) { 36 return DoRequest("CONNECT", url, data...) 37 } 38 39 func Options(url string, data ...interface{}) (*ClientResponse, error) { 40 return DoRequest("OPTIONS", url, data...) 41 } 42 43 func Trace(url string, data ...interface{}) (*ClientResponse, error) { 44 return DoRequest("TRACE", url, data...) 45 } 46 47 // 该方法支持二进制提交数据 48 func DoRequest(method, url string, data ...interface{}) (*ClientResponse, error) { 49 return NewClient().DoRequest(method, url, data...) 50 } 51 52 // GET请求并返回服务端结果(内部会自动读取服务端返回结果并关闭缓冲区指针) 53 func GetContent(url string, data ...interface{}) string { 54 return RequestContent("GET", url, data...) 55 } 56 57 // PUT请求并返回服务端结果(内部会自动读取服务端返回结果并关闭缓冲区指针) 58 func PutContent(url string, data ...interface{}) string { 59 return RequestContent("PUT", url, data...) 60 } 61 62 // POST请求并返回服务端结果(内部会自动读取服务端返回结果并关闭缓冲区指针) 63 func PostContent(url string, data ...interface{}) string { 64 return RequestContent("POST", url, data...) 65 } 66 67 // DELETE请求并返回服务端结果(内部会自动读取服务端返回结果并关闭缓冲区指针) 68 func DeleteContent(url string, data ...interface{}) string { 69 return RequestContent("DELETE", url, data...) 70 } 71 72 func HeadContent(url string, data ...interface{}) string { 73 return RequestContent("HEAD", url, data...) 74 } 75 76 func PatchContent(url string, data ...interface{}) string { 77 return RequestContent("PATCH", url, data...) 78 } 79 80 func ConnectContent(url string, data ...interface{}) string { 81 return RequestContent("CONNECT", url, data...) 82 } 83 84 func OptionsContent(url string, data ...interface{}) string { 85 return RequestContent("OPTIONS", url, data...) 86 } 87 88 func TraceContent(url string, data ...interface{}) string { 89 return RequestContent("TRACE", url, data...) 90 } 91 92 // 请求并返回服务端结果(内部会自动读取服务端返回结果并关闭缓冲区指针) 93 func RequestContent(method string, url string, data ...interface{}) string { 94 return NewClient().DoRequestContent(method, url, data...) 95 }