英文:
MissingRequestHeaderException on production but not on local
问题
在生产环境中调用GET控制器时,出现以下异常:
Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'user_id' for method parameter type String is not present]
如果我尝试使用Postman,则会得到400 Bad Request,在本地运行正常。
这是我的控制器:
@GetMapping(path = "/get")
public ResponseEntity<UserDto> getUserInformationById(@RequestHeader("user_id") final String id){
UserDto userDto = userInformationService.getUserInformationById(id);
if (userDto==null)
return ResponseEntity.notFound().build();
return ResponseEntity.ok(userDto);
}
为什么在生产环境中失败,而在本地环境中没有问题?相同类的其他类似端点正常工作,我漏掉了什么?
英文:
I'm getting the next exeption when I call GET controller in production, in local works fine:
Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'user_id' for method parameter type String is not present]
If I try using postman I got 400 Bad Request, in local works fine.
Here is my controler
@GetMapping(path ="/get")
public ResponseEntity <UserDto> getUserInformationById(@RequestHeader("user_id") final String id){
UserDto userDto = userInformationService.getUserInformationById(id);
if (userDto==null)
return ResponseEntity.notFound().build();
return ResponseEntity.ok(userDto);
}
Why is failing on production but not in local? another similar endpoints of the same class work fine, what am I missing?
答案1
得分: 1
我通过从标题中删除下划线解决了这个问题,我使用了 userId
,然后它就正常工作了。
在这里 你可以阅读更多相关信息。
英文:
I solved the issue by removing the underscore from the headers, I used userId
instead, and it worked.
Here you can read more about it
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论