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

API 里的 post json 模式下 Content-Type: application/json 校验能否采用包含匹配而非完全匹配?部分软件发送 http 请求时会自动附带 Content-Type: application/json; charset=utf-8 #130

Open
4 tasks done
zj1123581321 opened this issue Feb 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@zj1123581321
Copy link

zj1123581321 commented Feb 1, 2024

例行检查

  • 我已确认目前没有类似 issue
  • 我已确认我已升级到最新版本
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述
我使用 Postman 调用项目 API 发送 Post Json 请求,一切正常。
我使用 Quicker软件 您的指尖工具箱 - Quicker 的 http 模块发送则会报错,抓包发现是因为它的 Header 为:

Content-Type: application/json; charset=utf-8

image

而项目 API 校验采用完全匹配形式,所以就会报错。
复现步骤
以上述 header 在 postman 中模拟测试即可复现。

预期结果
能否将 API 的校验方式修改为【包含】?让项目更健壮?

@zj1123581321 zj1123581321 added the bug Something isn't working label Feb 1, 2024
@zjy4fun
Copy link

zjy4fun commented May 22, 2024

if c.Request.Header.Get("Content-Type") == "application/json" {

改为

contentType := c.Request.Header.Get("Content-Type")
mimeType := strings.Split(contentType, ";")[0]
if mimeType == "application/json" {
//...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants