2016-01-18 07:41
浏览 2.2k

Golang NewRequest将POST参数传递给API进行测试

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?


图片转代码服务由CSDN问答提供 功能建议

这是我的测试方法,它创建一个新请求并传递POST参数。</ p> < pre> url1:=“ / api / addprospect” data:= url.Values {} data.Add(“ customer_name”,“ value”) b:= bytes.NewBuffer([] byte(data。 Encode())) request,错误:= http.NewRequest(“ POST”,serverHttp.URL + url1,b) res,错误:= http.DefaultClient.Do(request) </ code> </ pre >

问题是url的函数处理程序未获取 POST参数</ code>。</ p>

能否请我帮忙 设置正确的请求?</ p>

谢谢</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题