nifcloud: fix API requests (#2039)

This commit is contained in:
Ludovic Fernandez 2023-10-18 11:53:04 +02:00 committed by GitHub
parent 52990b3c9e
commit c9ff534e39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,10 +149,9 @@ func (c *Client) sign(req *http.Request) error {
} }
func newXMLRequest(ctx context.Context, method string, endpoint *url.URL, payload any) (*http.Request, error) { func newXMLRequest(ctx context.Context, method string, endpoint *url.URL, payload any) (*http.Request, error) {
buf := new(bytes.Buffer) body := new(bytes.Buffer)
if payload != nil { if payload != nil {
body := new(bytes.Buffer)
body.WriteString(xml.Header) body.WriteString(xml.Header)
err := xml.NewEncoder(body).Encode(payload) err := xml.NewEncoder(body).Encode(payload)
if err != nil { if err != nil {
@ -160,7 +159,7 @@ func newXMLRequest(ctx context.Context, method string, endpoint *url.URL, payloa
} }
} }
req, err := http.NewRequestWithContext(ctx, method, endpoint.String(), buf) req, err := http.NewRequestWithContext(ctx, method, endpoint.String(), body)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to create request: %w", err) return nil, fmt.Errorf("unable to create request: %w", err)
} }