fix body building
parent
508da7f9cb
commit
f0a5dd5025
17
lib.go
17
lib.go
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue