diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index fb19a9c1d..727fb4344 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -188,10 +188,10 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) { switch { case h.Method == "GET": - requestURL.RawQuery = params.Encode() for k, v := range h.Parameters { params.Add(k, v) } + requestURL.RawQuery = params.Encode() case h.Method == "POST": requestURL.RawQuery = "" diff --git a/plugins/inputs/httpjson/httpjson_test.go b/plugins/inputs/httpjson/httpjson_test.go index 972ffb83c..6a98bbad3 100644 --- a/plugins/inputs/httpjson/httpjson_test.go +++ b/plugins/inputs/httpjson/httpjson_test.go @@ -222,17 +222,25 @@ func TestHttpJson200(t *testing.T) { // Test litecoin sample output func TestHttpJsonLiteCoin(t *testing.T) { + params := map[string]string{ + "api_key": "mykey", + } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + err := r.ParseForm() + assert.NoError(t, err) + key := r.Form.Get("api_key") + assert.Equal(t, "mykey", key) w.WriteHeader(http.StatusOK) fmt.Fprintln(w, validJSON2) })) defer ts.Close() a := HttpJson{ - Servers: []string{ts.URL}, - Name: "", - Method: "GET", - client: RealHTTPClient{client: &http.Client{}}, + Servers: []string{ts.URL}, + Name: "", + Method: "GET", + Parameters: params, + client: RealHTTPClient{client: &http.Client{}}, } var acc testutil.Accumulator