Files
gf/.example/net/ghttp/client/upload/client.go

42 lines
934 B
Go
Raw Normal View History

2018-01-10 18:20:32 +08:00
package main
import (
2019-04-03 00:03:46 +08:00
"fmt"
"github.com/gogf/gf/frame/g"
"path/filepath"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
2018-01-10 18:20:32 +08:00
)
func SendXmlFile(gameId int, areaName string, filePath string) error {
path := filepath.FromSlash(filePath)
fmt.Println(path)
data := g.Map{
"gameName": gameId,
"area": areaName,
"file": "@file:" + path,
"contentType": "json",
}
if r, err := ghttp.Post("http://127.0.0.1:8199/upload", data); err != nil {
panic(err)
} else {
defer r.Close()
fmt.Println("ok")
}
return nil
}
2018-01-10 18:20:32 +08:00
func main() {
SendXmlFile(1, "xxx", "/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/net/ghttp/server/session.go")
return
2019-04-03 00:03:46 +08:00
path := "/home/john/Workspace/Go/github.com/gogf/gf/version.go"
r, e := ghttp.Post("http://127.0.0.1:8199/upload", "upload-file=@file:"+path)
2019-04-03 00:03:46 +08:00
if e != nil {
glog.Error(e)
} else {
fmt.Println(string(r.ReadAll()))
r.Close()
}
}