This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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)
return string(respBody), nil
}