Skip to content

Commit

Permalink
fix: polygon api form, incorrect signature issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed Aug 1, 2024
1 parent b698078 commit 869e2b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions polygon/api.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package polygon

import (
"bytes"
"context"
"crypto/sha512"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"sort"
Expand Down Expand Up @@ -77,12 +79,21 @@ func buildRequest(method, link string, params url.Values) (*http.Request, error)

return http.NewRequestWithContext(context.TODO(), method, link, nil)
case http.MethodPost:
buf := strings.NewReader(params.Encode())
buf := &bytes.Buffer{}
writer := multipart.NewWriter(buf)
for k, vals := range params {
for _, v := range vals {
if err := writer.WriteField(k, v); err != nil {
return nil, err
}
}
}
writer.Close()
req, err := http.NewRequestWithContext(context.TODO(), method, link, buf)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Type", writer.FormDataContentType())

return req, nil
default:
Expand Down

0 comments on commit 869e2b6

Please sign in to comment.