跳到正文
源码达人

golang 发送 application/x-www-form-urlencoded 类型请求

Golang 柠檬鱼

需要结合标准库url的Values结构体,比如:

postData := url.Values{}
postData.Add("name", "Chris")
postData.Add("language", "golang")

普通post请求可以直接使用http.Post方法,第二个参数为application/x-www-form-urlencoded,如:

response, err := http.Post("https://xorpay.com/api/pay/aid", "application/x-www-form-urlencoded", strings.NewReader(postData.Encode()))