经过 Postman 传递日期

huangapple go评论72阅读模式
英文:

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

要么采用以下解决方案之一:

  1. 推荐的解决方案:在代码中将 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

  2. 对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:

  1. Recommended solution: Replace dd-M-yyyy hh:mm:ss with dd-M-yyyy'T'hh:mm:ss in the code and then you can test it like meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020T14:30:00&end=30-9-2020T15:30:00&capacity=10.
  2. 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=10using 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.

huangapple
  • 本文由 发表于 2020年9月29日 22:27:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64121693.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定