zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.35k stars 3.96k forks source link

Error sending request with httpc, with array form #4363

Open Dongss opened 2 months ago

Dongss commented 2 months ago

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

  1. 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)
  1. 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):

More description

The problem seems like happening here: fmt.Sprint(v)

https://github.com/zeromicro/go-zero/blob/d5302f2dbe1ea23812c4775bedcbe6626f7641fb/rest/httpc/requests.go#L60

kesonan commented 2 months ago

Use json tag and post json instead.

 type MyRequest struct {
    Status   []string `json:"status,optional"` 
   }