Is FormData encoded by default? #890
-
I'm just digging into a bug in a library I have created, and I was wondering if I need to encode FormData before sending, e.g.: r := a.Client.R().SetHeader("Content-Type", "application/x-www-form-urlencoded").SetResult(&putResponse{}).SetHeader("Accept", "application/json").SetFormData(form)
r.FormData.Encode()
resp, err := r.Put(url)
if err != nil {
return err
} or if this is done automatically? I can't see anywhere in the code where it is done automatically, but I just wanted confirmation from a library maintainer/author before assuming this is the case ... Many thanks! 😃 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@michealroberts Thanks for reaching out. Resty does the Form data encoding and sets appropriate content type when request form data methods are used. You could use the search string Code reference: Lines 501 to 502 in a6a489b |
Beta Was this translation helpful? Give feedback.
-
@jeevatkm Many thanks for your response, I appreciate that. I searched Encode() but I wasn't sure if it needed to be explicitly / specifically called. |
Beta Was this translation helpful? Give feedback.
@michealroberts Thanks for reaching out.
Resty does the Form data encoding and sets appropriate content type when request form data methods are used. You could use the search string
SetForm
on Resty godoc to find those methods.Code reference:
resty/middleware.go
Lines 501 to 502 in a6a489b