package CommonUtil import ( "fmt" "io/ioutil" "net/http" "strings" ) /** 功能:POST请求 作者:吴缤 日期:2020-02-21 备注:data方式为id=123 */ func HttpPost(url string, data string) (string, error) { request, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data)) defer request.Body.Close() if err != nil { fmt.Printf("post data error:%v\n", err) return "", err } else { respBody, err := ioutil.ReadAll(request.Body) if err != nil { return "", err } else { return string(respBody), nil } } }