package libs import ( "github.com/astaxie/beego/httplib" "errors" "crypto/tls" ) type Http struct { } func NewHttp()*Http { return new(Http) } func (http *Http)Post(url string,params map[string]interface{}) string { request := httplib.Post(url).Debug(true) setHeader(request) setParams(params,request) response,err := request.String() if err != nil{ errors.New(err.Error()) } return response } func (http *Http)Get(url string,params map[string]interface{}) string { request := httplib.Get(url).Debug(true) setParams(params,request) setHeader(request) response,err := request.String() if err != nil{ errors.New(err.Error()) } return response } func setParams(params map[string]interface{},request *httplib.BeegoHTTPRequest) { for k,v := range params { request.Param(k,ConvertString(v)) } request.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) } func setHeader(request *httplib.BeegoHTTPRequest) { request.Header("Accept-Encoding","gzip,deflate,sdch") request.Header("Content-Type","application/json;charset=utf-8") request.Header("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36") }