本文整理汇总了Golang中github.com/astaxie/beego/httplib.Post函数的典型用法代码示例。如果您正苦于以下问题:Golang Post函数的具体用法?Golang Post怎么用?Golang Post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Post函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SendSmsNew
/**
* 短信接口-新
*/
func SendSmsNew(phone, msg string) (err error) {
defer func() {
if x := recover(); x != nil {
errStr := fmt.Sprintf("Send sms fail: phone-%s, msg-%s, err-%v", phone, msg, x)
err = errors.New(errStr)
}
}()
phone = strings.TrimSpace(phone)
msg = strings.TrimSpace(msg)
if phone == "" || msg == "" {
return errors.New("无效参数")
}
req := httplib.Post("http://sms.uboxol.com/send_sms").SetTimeout(CONNECT_TIME_OUT, READ_WRITE_TIME_OUT).Header("Content-Type", "application/x-www-form-urlencoded")
req.Param("phone", phone)
req.Param("msg", msg)
req.Param("caller", "predetermine")
resp := &SmsResp{}
err = req.ToJson(resp)
fmt.Println(resp, err.Error())
return nil
}
开发者ID:NotBadPad,项目名称:go-learn,代码行数:28,代码来源:main.go
示例2: GetToken
// 获取github token
func (this *CheckController) GetToken() {
ok, data := func() (bool, interface{}) {
//获取并注销session
if this.GetSession("state") == nil {
return false, "请求已失效"
}
state := this.GetSession("state").(int32)
this.DelSession("state")
//验证state是否正确
postState, _ := this.GetInt32("state")
if postState != state {
return false, "state错误"
}
req := httplib.Post("https://github.com/login/oauth/access_token")
req.Param("client_id", beego.AppConfig.String("ClientId"))
req.Param("client_secret", beego.AppConfig.String("ClientSecret"))
req.Param("code", this.GetString("code"))
result, _ := req.String()
return true, result
}()
this.Data["json"] = map[string]interface{}{
"ok": ok,
"data": data,
}
this.ServeJson()
}
开发者ID:tzq668766,项目名称:avatar,代码行数:32,代码来源:check.go
示例3: DownloadDataSetSplit
func (m MasterApi) DownloadDataSetSplit(id, splitNumber, index int64) (string, error) {
req := httplib.Post(fmt.Sprintf("http://%s/v1/data_set/download", m.Hostname))
req = req.Param("id", strconv.FormatInt(id, 10))
req = req.Param("splitNumber", strconv.FormatInt(splitNumber, 10))
req = req.Param("index", strconv.FormatInt(index, 10))
resp, err := req.Response()
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", ErrApiFailed
}
filename := strings.TrimPrefix(resp.Header.Get("Content-Disposition"), "attachment; filename=")
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
err = ioutil.WriteFile("../tmp/"+filename, body, 0)
if err != nil {
return "", err
}
return filename, nil
}
开发者ID:CalvinNeo,项目名称:EasyMLPlatform,代码行数:31,代码来源:master_api.go
示例4: main
func main() {
/*defer func(){
recover()
fmt.Println("recover from panic")
}()
*/
//post**********************
req := httplib.Post("http://localhost:8080/users")
for i := 1; i < 10000; i++ {
//req.Param("id",fmt.Sprintf("%d",i))
//req.Param("name",fmt.Sprintf("name%d",i))
// fmt.Println(i)
// req.Param("id","1")
//req.Param("{\"name\":\"jac\"}")
//req.Param("name","hehe")
req.Body(fmt.Sprintf("{\"name\":\"jac%d\"}", i)) //for json ,must use Body method,key=value is not right
result, err := req.String()
if err != nil {
fmt.Println("error")
fmt.Println(err)
} else {
fmt.Println(result)
}
}
/*
str, err := httplib.Get("http://localhost:8080/users").String()
if err != nil {
//t.Fatal(err)
fmt.Println(err)
//panic("error in httplib")
}
fmt.Println(str)
*/
}
开发者ID:jchjjj,项目名称:learnGo,代码行数:34,代码来源:httplib.go
示例5: AcquireJobSlice
func (m MasterApi) AcquireJobSlice() (*models.JobSlice, error) {
req := httplib.Post(fmt.Sprintf("http://%s/v1/job_slice/acquire", m.Hostname))
resp, err := req.Response()
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
if resp.StatusCode == 204 {
return nil, ErrNoMoreData
} else {
return nil, ErrApiFailed
}
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
js := models.JobSlice{}
err = json.Unmarshal(body, &js)
if err != nil {
return nil, err
}
return &js, nil
}
开发者ID:CalvinNeo,项目名称:EasyMLPlatform,代码行数:30,代码来源:master_api.go
示例6: AcquireId
func (m MasterApi) AcquireId() (int64, error) {
req := httplib.Post(fmt.Sprintf("http://%s/v1/node/acquire", m.Hostname))
resp, err := req.Response()
if err != nil {
return -1, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return -1, ErrApiFailed
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return -1, err
}
id, err := strconv.ParseInt(string(body), 10, 64)
if err != nil {
return -1, err
}
return id, nil
}
开发者ID:CalvinNeo,项目名称:EasyMLPlatform,代码行数:25,代码来源:master_api.go
示例7: main
func main() {
defer func() {
if x := recover(); x != nil {
fmt.Println(x)
}
}()
req := httplib.Post(`http://192.168.8.30:8084/rest/release/soldout/`)
req.Header("Content-type", "text/plain;charset=UTF-8")
data := `{"vmCodes":[{"vmCode":"0001407","sn":"223389047060430848","ctime":"2014-09-08 00:00:01"},{"vmCode":"0001407","sn":"256","ctime":"2014-09-08 00:00:01"}]}`
fmt.Println(data)
req.Param("data", data)
// resp := &ApiResp{}
str, err := req.String()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(str)
// // err := req.ToJson(resp)
// if err != nil {
// return
// }
// var sellResults []*SellResult
// //获取body数据
// err = GetRespBodyData(resp, &sellResults)
// fmt.Println(resp.Head, sellResults)
return
}
开发者ID:NotBadPad,项目名称:go-learn,代码行数:30,代码来源:main1.go
示例8: UserBlockQuery
//获取被封禁用户 方法
func (rcServer *RCServer) UserBlockQuery() ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_USER_BLOCK_QUERY + rcServer.format
req := httplib.Post(destinationUrl)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:8,代码来源:RCServer.go
示例9: GetPostHttpRequestData
/**
* 获取http请求结果,只支持post,返回结构自定义
* url:请求地址
* params:post参数
* data:返回数据
*/
func GetPostHttpRequestData(url string, params map[string]string, respData interface{}) (err error) {
defer func() {
if x := recover(); x != nil {
errStr := fmt.Sprintf("get post fail: params-%v , err-%v", params, x)
err = errors.New(errStr)
}
}()
begin := time.Now().UnixNano()
req := httplib.Post(url).SetTimeout(CONNECT_TIME_OUT, READ_WRITE_TIME_OUT).Header("Content-Type", "application/x-www-form-urlencoded")
beego.Info("Request url:", url, params)
if params != nil && len(params) > 0 {
for key, value := range params {
req.Param(key, value)
}
}
err = req.ToJson(respData)
if err != nil {
return
}
end := time.Now().UnixNano()
beego.Info("Http response:", respData, ", cost:", end-begin)
return
}
开发者ID:NotBadPad,项目名称:go-learn,代码行数:31,代码来源:httpHelper.go
示例10: getRepo
// getRepo downloads package data and returns 'Package' by given import path and tag.
// It returns error when error occurs in the underlying functions.
func getRepo(client *http.Client, path, tag, ptag string) (pdoc *hv.Package, err error) {
switch {
case utils.IsGoRepoPath(path):
pdoc, err = getStandardDoc(client, path, tag, ptag)
case utils.IsValidRemotePath(path):
pdoc, err = getStatic(client, path, tag, ptag)
if err == errNoMatch {
pdoc, err = getDynamic(client, path, tag, ptag)
}
default:
return nil, errors.New(
fmt.Sprintf("doc.getRepo -> No match( %s:%s )", path, tag))
}
if pdoc == nil {
return nil, err
}
pdoc.PkgVer = hv.PACKAGE_VER
// Render README.
for name, content := range pdoc.Readme {
p, err := httplib.Post("https://api.github.com/markdown/raw?"+GetGithubCredentials()).
Header("Content-Type", "text/plain").Body(content).Bytes()
if err != nil {
return nil, errors.New(
fmt.Sprintf("doc.getRepo -> Render README( %s:%s ): %v", path, tag, err))
}
pdoc.Readme[name] = p
}
return pdoc, err
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:34,代码来源:crawl.go
示例11: backUp
//comp file
func backUp() {
backUpFile := beego.AppName + "_" + time.Now().Format("060102") + ".zip"
fw, err := os.Create(backUpFile)
if err != nil {
beego.Error(err)
return
}
defer fw.Close()
zw := zip.NewWriter(fw)
defer zw.Close()
walk := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
src, _ := os.Open(path)
defer src.Close()
h := &zip.FileHeader{Name: path, Method: zip.Deflate, Flags: 0x800}
fileName, _ := zw.CreateHeader(h)
io.Copy(fileName, src)
zw.Flush()
return nil
}
if err := filepath.Walk(enum.CONST.DBNAME, walk); err != nil {
beego.Error(err)
return
}
if err := filepath.Walk(enum.CONST.UPLOADPATH, walk); err != nil {
beego.Error(err)
return
}
//file upload
req := httplib.Post(url)
req.Header("Authorization", dropboxAuthorization)
req.Header("Dropbox-API-Arg", fmt.Sprintf(argF, beego.AppName, backUpFile))
req.Header("Content-Type", "application/octet-stream")
data, err := ioutil.ReadFile(backUpFile)
if err != nil {
beego.Error(err)
return
}
req.Body(data)
resp, err := req.SendOut()
if err != nil || resp.StatusCode != http.StatusOK {
beego.Error(err, resp)
}
//file delete
os.Remove(backUpFile)
}
开发者ID:elvizlai,项目名称:Blog,代码行数:60,代码来源:backup.go
示例12: test3
func test3() {
url := "http://localhost:8081/test"
req := httplib.Post(url)
req.Param("username", "guojing")
req.Param("password", "123456")
b, _ := req.Bytes()
fmt.Println(string(b))
}
开发者ID:NotBadPad,项目名称:go-learn,代码行数:8,代码来源:main.go
示例13: ChatroomQuery
//查询聊天室信息 方法
func (rcServer *RCServer) ChatroomQuery(chatroomId string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_CHATROOM_QUERY + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("chatroomId", chatroomId)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:9,代码来源:RCServer.go
示例14: MessageHistoryDelete
//消息历史记录删除 方法
//说明:删除 APP 内指定某天某小时内的所有会话消息记录
func (rcServer *RCServer) MessageHistoryDelete(date string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_MESSAGE_HISTORY_DELETE + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("date", date)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:10,代码来源:RCServer.go
示例15: UserBlackQuery
//获取某用户的黑名单列表 方法
func (rcServer *RCServer) UserBlackQuery(userId string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_USER_BLACK_QUERY + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("userId", userId)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:9,代码来源:RCServer.go
示例16: UserUnblock
//解除用户封禁 方法
func (rcServer *RCServer) UserUnblock(userId string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_USER_UNBLOCK + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("userId", userId)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:9,代码来源:RCServer.go
示例17: UserCheckOnline
//检查用户在线状态 方法
//请不要频繁循环调用此接口,而是选择合适的频率和时机调用,此接口设置了一定的频率限制。
func (rcServer *RCServer) UserCheckOnline(userId string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_USER_CHECK_ONLINE + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("userId", userId)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:10,代码来源:RCServer.go
示例18: ChatroomCreat
//创建聊天室 方法
func (rcServer *RCServer) ChatroomCreat(chatroomId, chatroomName string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_CHATROOM_CREATE + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("chatroom["+chatroomId+"]", chatroomName)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:9,代码来源:RCServer.go
示例19: GroupRefresh
//刷新群组信息 方法
func (rcServer *RCServer) GroupRefresh(groupId, groupName string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_GROUP_REFRESH + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("groupId", groupId)
req.Param("groupName", groupName)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:10,代码来源:RCServer.go
示例20: GroupDismiss
//解散群组 方法
//将该群解散,所有用户都无法再接收该群的消息。
func (rcServer *RCServer) GroupDismiss(userId, groupId string) ([]byte, error) {
destinationUrl := rcServer.apiUrl + RC_GROUP_DISMISS + rcServer.format
req := httplib.Post(destinationUrl)
req.Param("userId", userId)
req.Param("groupId", groupId)
fillHeader(req, rcServer)
byteData, err := req.Bytes()
return byteData, err
}
开发者ID:yuwnloyblog,项目名称:server-sdk-go,代码行数:11,代码来源:RCServer.go
注:本文中的github.com/astaxie/beego/httplib.Post函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论