From 8572fca487d124518e46f4fad1919cf98c5ae56a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 28 Jul 2024 18:27:42 +0300 Subject: fix bug where POST turned out to be a HTTP get when there are // in the URI --- internal/easyhttp/easyhttp.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'internal/easyhttp') diff --git a/internal/easyhttp/easyhttp.go b/internal/easyhttp/easyhttp.go index 32a3069..ce3d53b 100644 --- a/internal/easyhttp/easyhttp.go +++ b/internal/easyhttp/easyhttp.go @@ -16,7 +16,7 @@ func Get(ctx context.Context, uri, apiKey string) ([]byte, error) { bytes []byte ) - req, err := http.NewRequestWithContext(ctx, "GET", uri, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) if err != nil { return bytes, fmt.Errorf("%s: %w", uri, err) } @@ -48,11 +48,12 @@ func GetData[T any](ctx context.Context, uri, apiKey string, data *T) error { } func Post(ctx context.Context, uri, apiKey string, data []byte) ([]byte, error) { - req, err := http.NewRequestWithContext(ctx, "POST", uri, bytes.NewBuffer(data)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, bytes.NewBuffer(data)) if err != nil { return []byte{}, fmt.Errorf("%s: %w", uri, err) } + req.Header.Set("Content-Type", "application/json") req.Header.Set("X-API-KEY", apiKey) client := &http.Client{} -- cgit v1.2.3