完整的http请求代码就不放了,直接写上构造form-data参数的代码。
const (
http_address = "http://yourIP:8080/****"
)
// 用url.values方式构造form-data参数
formValues := url.Values{}
formValues.Set("first",firstData)
formValues.Set("second",secondData)
formDataStr := formValues.Encode()
formDataBytes := []byte(formDataStr )
formBytesReader := bytes.NewReader(formDataBytes )
//生成post请求
client := &http.Client{}
req, err := http.NewRequest("POST", http_address, formBytesReader )
if err != nil {
// handle error
log.Fatal("生成请求失败!",err)
return
}
//注意别忘了设置header
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
//Do方法发送请求
resp, err := client.Do(req)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)