diff --git a/net/ghttp/ghttp_client_api.go b/net/ghttp/ghttp_client_api.go index dc6460732..bee125190 100644 --- a/net/ghttp/ghttp_client_api.go +++ b/net/ghttp/ghttp_client_api.go @@ -8,8 +8,8 @@ package ghttp // Get is a convenience method for sending GET request. // NOTE that remembers CLOSING the response object when it'll never be used. -func Get(url string) (*ClientResponse, error) { - return DoRequest("GET", url) +func Get(url string, data ...interface{}) (*ClientResponse, error) { + return DoRequest("GET", url, data...) } // Put is a convenience method for sending PUT request. diff --git a/net/ghttp/ghttp_client_request.go b/net/ghttp/ghttp_client_request.go index a032c89f4..13ce3e171 100644 --- a/net/ghttp/ghttp_client_request.go +++ b/net/ghttp/ghttp_client_request.go @@ -12,6 +12,7 @@ import ( "errors" "fmt" "github.com/gogf/gf/text/gregex" + "github.com/gogf/gf/text/gstr" "io" "mime/multipart" "net/http" @@ -205,6 +206,14 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (*ClientResp if len(data) > 0 { param = BuildParams(data[0]) } + if strings.EqualFold("GET", method) && param != "" { + if gstr.Contains(url, "?") { + url += "&" + param + } else { + url += "?" + param + } + param = "" + } req, err := http.NewRequest(strings.ToUpper(method), url, bytes.NewReader([]byte(param))) if err != nil { return nil, err