Use http.NewRequest() for creating requests, issue #1004
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -108,21 +107,13 @@ func (api *ZabbixAPI) request(ctx context.Context, method string, params ZabbixA
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var body io.Reader
|
req, err := http.NewRequest(http.MethodPost, api.url.String(), bytes.NewBuffer(reqBodyJSON))
|
||||||
body = bytes.NewReader(reqBodyJSON)
|
if err != nil {
|
||||||
rc, ok := body.(io.ReadCloser)
|
return nil, err
|
||||||
if !ok && body != nil {
|
|
||||||
rc = ioutil.NopCloser(body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &http.Request{
|
req.Header.Set("Content-Type", "application/json")
|
||||||
Method: "POST",
|
req.Header.Set("User-Agent", "Grafana/grafana-zabbix")
|
||||||
URL: api.url,
|
|
||||||
Header: map[string][]string{
|
|
||||||
"Content-Type": {"application/json"},
|
|
||||||
},
|
|
||||||
Body: rc,
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := makeHTTPRequest(ctx, api.httpClient, req)
|
response, err := makeHTTPRequest(ctx, api.httpClient, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user