[Go]GO语言实现发送post请求

前端之家收集整理的这篇文章主要介绍了[Go]GO语言实现发送post请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//Post("http://xxxx","application/json;charset=utf-8",[]byte("{'aaa':'bbb'}"))
func Post(url string,contentType byte) (string,error) {
    res,err := http.Post(url,contentType,strings.NewReader((body)))
    if err != nil {
        return "" IoUtil.ReadAll(res.Body)
    return (content),nil
}

发送一个JSON类型的请求

Post("http://xxxx",[]byte("{'aaa':'bbb'}"))

 

猜你在找的Go相关文章