Error sending request with httpc, with array form
Describe the bug
Sending request with httpc, with array form ?status=["Processing", "Cancelled"]
Server got error:
fullName: `status`, error: `string: `[Processing Cancelled]`, error: `invalid character 'P' looking for beginning of value``
To Reproduce
- The code is API defination:
type MyRequest struct {
Status []string `form:"status,optional"`
}
code:
req := types.MyRequest{
Status: []string{"Processing", "Cancelled"}
}
httpc.Do(ctx, "GET", "localhost:80", req)
-
The error is server side got error:
fullName: `status`, error: `string: `[Processing Cancelled]`, error: `invalid character 'P' looking for beginning of value``
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Environments (please complete the following information):
- OS: [Linux]
- go-zero version [1.6.3]
- goctl version [1.5.6]
More description
The problem seems like happening here: fmt.Sprint(v)
https://github.com/zeromicro/go-zero/blob/d5302f2dbe1ea23812c4775bedcbe6626f7641fb/rest/httpc/requests.go#L60
Use json tag and post json instead.
type MyRequest struct {
Status []string `json:"status,optional"`
}
Using this definition, in the old version (1.5.5), form ?status=["a","b"] this will parse normally, in the new version (1.8.0) parsing error, but in 1.8.0 using form ?status=a,b or ?status=a&status=b will parse normally
Using this definition, in the old version (1.5.5), form
status:["a","b"]this will parse normally, in the new version (1.8.0) parsing error, but in 1.8.0 using formstatus: a,bwill parse normally
I've used this method before and I can't upgrade the go-zero version because of this issue