fix body building

master
Paulo Simão 2021-10-09 10:43:06 -03:00
parent 508da7f9cb
commit f0a5dd5025
1 changed files with 8 additions and 9 deletions

17
lib.go
View File

@ -39,15 +39,9 @@ func (c *Cli) Do(method string, strurl string, body []byte) (*http.Response, err
}
strurl = addr + strurl
}
req, err := http.NewRequest(method, strurl, bytes.NewReader(body))
if err != nil {
return nil, err
}
if c.headers != nil {
for k, v := range c.headers {
req.Header.Set(k, v)
}
}
var req *http.Request
var err error
if body != nil && len(body) > 0 {
req, err = http.NewRequest(method, strurl, io.NopCloser(bytes.NewReader(body)))
@ -57,6 +51,11 @@ func (c *Cli) Do(method string, strurl string, body []byte) (*http.Response, err
if err != nil {
return nil, err
}
if c.headers != nil {
for k, v := range c.headers {
req.Header.Set(k, v)
}
}
return c.cli.Do(req)
}
func (c *Cli) DoJson(method string, strurl string, i interface{}, o interface{}) (err error) {