fix requests

nats
Paulo Simão 2021-10-10 13:15:15 -03:00
parent e0a0904c90
commit 42df57854b
1 changed files with 10 additions and 9 deletions

View File

@ -41,15 +41,10 @@ func (c *Cli) HttpDo(method string, strurl string, body []byte) (*http.Response,
}
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)))
@ -59,6 +54,12 @@ func (c *Cli) HttpDo(method string, strurl string, body []byte) (*http.Response,
if err != nil {
return nil, err
}
if c.headers != nil {
for k, v := range c.headers {
req.Header.Set(k, v)
}
}
req.Header.Set("X-API-KEY", apikey)
req.Header.Set("Content-Type", "application/json")
return c.cli.Do(req)