英文:
Pass date through postman
问题
这是我的控制器:
@GetMapping("/checkMeetingRoomAvailability")
public @ResponseBody ResponseDto checkMeetingRoomAvailability(
@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date begin,
@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date end,
@RequestParam Integer capacity) {
return meetingRoomServiceLocal.checkMeetingRoomAvailability(begin, end, capacity);
}
当我使用 Postman 提供输入时,它返回 400 错误请求。
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
我无法确定为什么会出现此错误。
英文:
This is my controller:
@GetMapping("/checkMeetingRoomAvailability")
public @ResponseBody ResponseDto checkMeetingRoomAvailability(@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date begin,
@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date end, @RequestParam Integer capacity) {
return meetingRoomServiceLocal.checkMeetingRoomAvailability(begin, end, capacity);
}
when i pass input using postman its giving 400 bad request.
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
i am unable to figure out why i am getting this error.
答案1
得分: 0
要么采用以下解决方案之一:
-
推荐的解决方案:在代码中将
dd-M-yyyy hh:mm:ss
替换为dd-M-yyyy'T'hh:mm:ss
,然后您可以像这样测试它:meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020T14:30:00&end=30-9-2020T15:30:00&capacity=10
。 -
对URL进行编码,以便日期和时间之间的空格可以适当地进行编码,例如,您可以使用某个编码工具对
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
进行编码,例如 https://www.urlencoder.org/,然后在 Postman 中使用编码后的URL。我不建议这样做,因为它将强制您的客户在向服务器发送请求之前对URL进行编码。
英文:
Either of the following solutions will work:
- Recommended solution: Replace
dd-M-yyyy hh:mm:ss
withdd-M-yyyy'T'hh:mm:ss
in the code and then you can test it likemeetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020T14:30:00&end=30-9-2020T15:30:00&capacity=10
. - Encode the URL so that the space between date and time can be encoded appropriately e.g. as a test, you can encode
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
using some encoding tool e.g. https://www.urlencoder.org/ and use the encoded URL in Postman. I do not recommend this as it will force your clients to encoded URL before they can send a request to your server.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论