字符串类型的方法参数缺少请求标头“client_id”

问题描述 投票:0回答:1

在向 Spring Boot Rest API 发出 post 请求时,它会抛出 Servlet 请求绑定异常,并显示错误消息“字符串类型的方法参数缺少请求标头‘client_id’”。即使在标头中传递了 client_id 字段后也是如此。

这种情况仅发生在我们的一个测试环境中。 请求标头的名称中包含“_”下划线。相同的代码在本地工作。这里可能有什么问题。是否与部署文件或代码相关问题有关。

curl --location --request POST 'http://localhost:7087/test' \
--header 'accept: application/json' \
--header 'client_id: test' \
--header 'Content-Type: application/json' \
--data-raw '{
    "data": "test"
}'




 @PostMapping(path = "/test", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Object pushMsg(@Valid @RequestBody String data, 
            @RequestHeader("client_id") String clientId) {
            return null;
    }
java spring-boot azure-aks request-headers
1个回答
0
投票

检查是否与此类相关:

[HTTP 服务器禁止 HTTP 标头名称中使用下划线][1] https://stackoverflow.com/questions/22856136/why-do-http-servers-forbid-underscores-in-http-header-names

© www.soinside.com 2019 - 2024. All rights reserved.