将java日期传递给rest查询参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18716095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pass java date into rest query parameter
提问by RNJ
I have
我有
@PUT
@Path("{id}")
public Response modify(@PathParam("id") Integer id,
@QueryParam("user") String user, @QueryParam("time") Date time) {....
I am trying to use RestClient to call this web service (the above is actually a cut down version of what I have)
我正在尝试使用 RestClient 来调用此 Web 服务(上面实际上是我所拥有的缩减版本)
When I call
当我打电话
..../123?user=user1
I hit the web service. As soon as I add time I get a 403 Forbidden message
我点击了网络服务。一旦我增加时间,我就会收到一条 403 Forbidden 消息
..../123?user=user1&time=2013-09-10T20:00:00Z
Even if I pass nothing into the time query parameter I get the 403.
即使我没有将任何内容传递给时间查询参数,我也会得到 403。
Is there anything difference about passing the java dates?
传递java日期有什么区别吗?
Thank in advance
预先感谢
回答by Juned Ahsan
One observation: It seems you are adding an extra slash(/) before your query params:
一个观察结果:您似乎在查询参数之前添加了一个额外的斜线(/):
change this
改变这个
..../123/?user=user1&time=2013-09-10T20:00:00Z
to
到
..../123?user=user1&time=2013-09-10T20:00:00Z
Second thing is that you may have to encode your URL to send the date properly to server
第二件事是您可能必须对您的 URL 进行编码才能将日期正确发送到服务器
回答by hanish.kh
It's not able to deserialize the String
to a Date
. Two options are either you can modify the date string as accepted by the date class or use another form, such as a long
value.
这是不能够反序列化String
到Date
。两个选项是您可以修改日期类接受的日期字符串或使用其他形式,例如long
值。