[beego]httplib Put方法的Param不生效

2024-06-26 664 views
1
  1. What version of Go and beego are you using (bee version)?

    | \ | |/ / __ | \ / \ / \ | |/ /| /| / ___/ \| ___| v1.10.0

├── Beego : 1.12.1 ├── GoVersion : go1.13.4 ├── GOOS : windows ├── GOARCH : amd64 ├── NumCPU : 8 ├── GOPATH : D:\Go ├── GOROOT : E:\Go ├── Compiler : gc └── Date : Tuesday, 26 May 2020

  1. What operating system and processor architecture are you using (go env)? set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\XLL\AppData\Local\go-build set GOENV=C:\Users\XLL\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GONOPROXY=.corp.example.com set GONOSUMDB=.corp.example.com set GOOS=windows set GOPATH=D:\Go set GOPRIVATE=*.corp.example.com set GOPROXY=https://goproxy.io,direct set GOROOT=E:\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=E:\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD= set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\XLL\AppData\Local\Temp\go-build130861342=/tmp/go-build -gno-record-gcc-switches

我再使用httplib的Put方法时,通过Param()添加参数,没有效果

req := httplib.Put("http://user:password@192.168.0.10:8080/rest/api/2/user/password/")
req.Param("username", "2222")

返回的response为

&{http://user:password@192.168.0.10:8080/rest/api/2/user/password/ 0xc0000d8000 map[username:[2222]] map[] {false beegoServer 60000000000 60000000000 <nil> <nil> <nil> <nil> false true true 0} 0xc0000d6000 [] []}
{"errorMessages":["无论是 “用户名” 或 “按键” 的查询参数需要提供"],"errors":{}}

但是我在使用Post方式时,Param是可以生效的,是Put方法不支持Param还是我的使用错误,我看文档的描述是这样的 image 十分期望能得到回复,谢谢

回答

5

app code

// @router /:id [put]
func (c *Test1Controller) Put() {
    logs.Info(`-->%+v`,c.Input().Get(`username`))
    logs.Info(`->%+v`,c.GetString(`username`,``))
    c.Data[`json`] = `ok`
    c.ServeJSON()
}

app out

2020/06/01 10:26:42.508 [I] [controller.go:218]  -->2222
2020/06/01 10:26:42.508 [I] [controller.go:218]  ->2222
2020/06/01 10:26:42.508 [D] [server.go:2802]  |      127.0.0.1| 200 |    195.496µs|   match| PUT      /v1/test5/1   r:/v1/test5/:id

test code

func TestBeegoPut(t *testing.T) {
    req := httplib.Put("http://127.0.0.1:18080/v1/test5/1")
    req.Debug(true)
    req.Param("username", "2222")
    s, e := req.String()
    logs.Info(`--> [%+v]`, s)
    Convey("Subject: Test Station Endpoint\n", t, func() {
        Convey("Error (1) Should Be nil", func() {
            So(e, ShouldEqual, nil)
        })
        Convey("The Result Should Be OK", func() {
            So(s, ShouldEqual, `"ok"`)
        })
    })
}

test out :

=== RUN   TestBeegoPut
2020/06/01 10:26:42.509 [I] [testing.go:909]  --> ["ok"]
..
2 total assertions

--- PASS: TestBeegoPut (0.01s)
PASS

i think you must check your code.

7

thank you

0

好的,谢谢您的回答,我去看看源码。 大佬能加一个WX或者QQ吗?我是一个运维,最近刚接触到Go,这里卡了我很长时间,很是气馁,如果您方便的话,希望您能加我。QQ:775808429
WX: q775808429 @guhan121