Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpx.parse error when the field's type in request is []byte #4215

Open
giantcroc opened this issue Jun 26, 2024 · 4 comments
Open

httpx.parse error when the field's type in request is []byte #4215

giantcroc opened this issue Jun 26, 2024 · 4 comments

Comments

@giantcroc
Copy link

giantcroc commented Jun 26, 2024

Describe the bug
httpx.parse error when the field's type in request is []byte
and I post the data body after json Marshal like '{"task":"base64 encoded data"}'.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is
  ApplyRequest {
  Task []byte `json:"task"`
  }
  ApplyResponse {
  ApplyResult string `json:"applyresult"`
  }
  1. The error is

    error: fullName: `task`, error: `string: `dGFza25hbWU6IHRhc2sxCmpvYmxpc3Q6Ci0gam9ibmFtZTogYnVpbGQKICBqb2J1cmw6IGh0dHA6Ly9qZW5raW5zLmV4YW1wbGUuY29tL2pvYi9CdWlsZFByb2plY3RBCiAgcGFyYW1ldGVyczoKICAgIG5vZGVsYWJlbDogbGludXgKICAgIGFyY2hpdGVjdHVyZTogeDg2XzY0CiAgICBwcm9kdWN0dHlwZTogYXBwbGljYXRpb24KICAgIHB5dGhvbnZlcnNpb246ICIzLjgiCiAgamVua2luc25hbWU6IGplbmtpbnNfbWFpbgogIHByaW9yaXR5OiAxCi0gam9ibmFtZTogdGVzdCBwcm9qZWN0IGIKICBqb2J1cmw6IGh0dHA6Ly9qZW5raW5zLmV4YW1wbGUuY29tL2pvYi9UZXN0UHJvamVjdEIKICBwYXJhbWV0ZXJzOgogICAgbm9kZWxhYmVsOiB3aW5kb3dzCiAgICBhcmNoaXRlY3R1cmU6IHg4Nl82NAogICAgcHJvZHVjdHR5cGU6IGxpYnJhcnkKICAgIHB5dGhvbnZlcnNpb246ICIzLjkiCiAgamVua2luc25hbWU6IGplbmtpbnNfdGVzdAogIHByaW9yaXR5OiAy`, error: `invalid character 'd' 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: [e.g. Linux]
  • go-zero version 1.6.5
  • goctl version goctl version 1.6.6 linux/amd64

More description
Add any other context about the problem here.

@giantcroc giantcroc changed the title httpx.parse error when the field in request is []byte httpx.parse error when the field's type in request is []byte Jun 26, 2024
@Owen-Zhang
Copy link

都base64了,为何不搞成string呢?

 ApplyRequest {
  Task string `json:"task"`
  }

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


It’s all base64, why not make it a string?

 ApplyRequest {
  Task string `json:"task"`
  }

@giantcroc
Copy link
Author

giantcroc commented Jun 28, 2024

都base64了,为何不搞成string呢?

 ApplyRequest {
  Task string `json:"task"`
  }

We use json.Marshal(ApplyRequest) to process the request struct in client,and base64 encoded data is the result of this process.

@kesonan
Copy link
Collaborator

kesonan commented Jun 29, 2024

Go-zero will not help you with type conversion, so your data type must be consistent with the input parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants