完善ghttp客户端示例

This commit is contained in:
John
2018-01-11 17:05:10 +08:00
parent 36ab7a0b05
commit 8da77b8da5
2 changed files with 5 additions and 6 deletions

View File

@ -1,10 +1,9 @@
package demo
import (
"gitee.com/johng/gf/g/os/glog"
"fmt"
"gitee.com/johng/gf/g/os/gfile"
"gitee.com/johng/gf/g/net/ghttp"
"fmt"
)
func Upload(r *ghttp.Request) {
@ -16,7 +15,7 @@ func Upload(r *ghttp.Request) {
gfile.PutBinContents("/tmp/" + fname, buffer)
r.Response.WriteString(fmt.Sprintf("%s upload success, input value:%s", fname, r.GetPostString("name")))
} else {
glog.Error(e)
r.Response.WriteString(e.Error())
}
}

View File

@ -2,13 +2,13 @@ package main
import (
"fmt"
"gitee.com/johng/gf/g/net/ghttp"
"gitee.com/johng/gf/g/os/glog"
"gitee.com/johng/gf/g/net/ghttp"
)
func main() {
path := "/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/version.go"
r, e := ghttp.Post("http://127.0.0.1:8199/upload?page=1", "name=john&upload-file=@file:" + path)
path := "/home/john/Workspace/Go/gitee.com/johng/gf/version.go"
r, e := ghttp.Post("http://127.0.0.1:8199/upload", "name=john&age=18&upload-file=@file:" + path)
if e != nil {
glog.Error(e)
} else {