From b7f007648a28a1c73c4d27c98f338733c7a3230d Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Sun, 21 Aug 2022 07:52:24 -0700 Subject: [PATCH] impl PostForm for custom client --- pkg/httpclient/client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/httpclient/client.go b/pkg/httpclient/client.go index 95598b11..3f094156 100644 --- a/pkg/httpclient/client.go +++ b/pkg/httpclient/client.go @@ -6,6 +6,8 @@ import ( "io" "io/ioutil" "net/http" + "net/url" + "strings" "sync" "sync/atomic" "time" @@ -15,6 +17,7 @@ type IHttpClient interface { Do(req *http.Request) (*http.Response, error) Get(url string) (*http.Response, error) Post(url, contentType string, body io.Reader) (resp *http.Response, err error) + PostForm(url string, data url.Values) (resp *http.Response, err error) } // Client special http client that can throttle requests per seconds (RPS). @@ -90,6 +93,10 @@ func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Respo return c.do(req) } +func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error) { + return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) +} + func (c *Client) Get(url string) (*http.Response, error) { return c.get(url) }