mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve ghttp.Client.Get
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user