github.com/gogf/gf@v1.16.9/.example/net/ghttp/client/upload/client.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "github.com/gogf/gf/frame/g" 6 "path/filepath" 7 8 "github.com/gogf/gf/net/ghttp" 9 "github.com/gogf/gf/os/glog" 10 ) 11 12 func SendXmlFile(gameId int, areaName string, filePath string) error { 13 path := filepath.FromSlash(filePath) 14 fmt.Println(path) 15 data := g.Map{ 16 "gameName": gameId, 17 "area": areaName, 18 "file": "@file:" + path, 19 "contentType": "json", 20 } 21 if r, err := ghttp.Post("http://127.0.0.1:8199/upload", data); err != nil { 22 panic(err) 23 } else { 24 defer r.Close() 25 fmt.Println("ok") 26 } 27 return nil 28 } 29 30 func main() { 31 SendXmlFile(1, "xxx", "/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/net/ghttp/server/session.go") 32 return 33 path := "/home/john/Workspace/Go/github.com/gogf/gf/version.go" 34 r, e := ghttp.Post("http://127.0.0.1:8199/upload", "upload-file=@file:"+path) 35 if e != nil { 36 glog.Error(e) 37 } else { 38 fmt.Println(string(r.ReadAll())) 39 r.Close() 40 } 41 }