revel 中 怎么发起一个http请求?

控制器admin1114 次浏览
import (
	"io/ioutil"
	"net/http"
)
func httpGet(url string) []byte {
	res, err := http.Get(url)
	if err != nil {
		revel.ERROR.Println(err)
	}

	body, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		revel.ERROR.Println(err)
	}

	return body
}
func httpPostForm(url string, data url.Values) []byte {
	res, err := http.PostForm(url, data)
	if err != nil {
		revel.ERROR.Println(err)
	}

	body, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		revel.ERROR.Println(err)
	}

	return body
}

 

共0个回复