Reputation: 591
This is my test method which creates a new request and passes POST param.
url1 := "/api/addprospect"
data := url.Values{}
data.Add("customer_name", "value")
b := bytes.NewBuffer([]byte(data.Encode()))
request, err := http.NewRequest("POST", serverHttp.URL+url1, b)
res, err := http.DefaultClient.Do(request)
The problem is the POST param
is not getting picked up by the function handler of the url.
Can you please help me with setting up right request?
Thanks
Upvotes: 0
Views: 1401
Reputation: 49187
You need to properly set the content-type header for your request.
request, err := http.NewRequest("POST", serverHttp.URL+url1, b)
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, err := http.DefaultClient.Do(request)
Upvotes: 1