I cannot seem to ready body element from XML request in my application.
I tried BodyParameter
from Go-restulf package below but it doesn't seem to work and it just returns nil.
// BodyParameter parses the body of the request (once for typically a POST or a PUT) and returns the value of the given name or an error.
func (r *Request) BodyParameter(name string) (string, error) {
err := r.Request.ParseForm()
if err != nil {
return "", err
}
return r.Request.PostFormValue(name), nil
}
Below is what I have currently on my file:
type Account struct {
title, firstName, lastName, email, dob, countryCode, addrLevel, addUnitType, addrUnitNo, addrAllotment, addrBuildingNo, addrStreetName, addrStreetType, addrStreet1, addrStreet2, addrCity, countryState, addrPostcode, telephone, mobile string
userName, password string
currency float32
challenge1 string
response1 string
AdminUser, AdminPass, Version string
}
func (api *ApiResource) create(request *restful.Request, response *restful.Response) {
account := &Account{AdminUser: user, AdminPass: pass, Version: version}
err := request.ReadEntity(account)
if err != nil {
response.WriteErrorString(http.StatusInternalServerError, err.Error())
return
}
fmt.Println(request.BodyParameter("UserName"))
}
Is there a reason why this isn't working as expected?