1 Star 0 Fork 0

golang库 / beego封装

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
request.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
李旭 提交于 2023-04-06 19:15 . first commit
package lxbeego
import (
"crypto/tls"
"github.com/astaxie/beego/httplib"
"io/ioutil"
"strings"
)
func PostBody(apiurl string, data map[string]interface{}) (content []byte, httpcode int, err error) {
req := httplib.Post(apiurl)
if strings.Contains(apiurl, "https://") {
req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
req.JSONBody(data)
resp, err := req.Response()
if err != nil {
return
}
httpcode = resp.StatusCode
content, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
return
}
func PostParam(apiurl string, data map[string]string) (content []byte, httpcode int, err error) {
req := httplib.Post(apiurl)
if strings.Contains(apiurl, "https://") {
req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
for k, v := range data {
req.Param(k, v)
}
resp, err := req.Response()
if err != nil {
return
}
httpcode = resp.StatusCode
content, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
return
}
func Get(apiurl string) (content []byte, httpcode int, err error) {
req := httplib.Get(apiurl)
if strings.Contains(apiurl, "https://") {
req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
resp, err := req.Response()
if err != nil {
return
}
httpcode = resp.StatusCode
content, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
return
}
1
https://gitee.com/lxgow/lxbeego.git
git@gitee.com:lxgow/lxbeego.git
lxgow
lxbeego
beego封装
9a692fdff14e

搜索帮助