简体   繁体   English

使用@POST或@PUT使用@QueryParam

[英]Rest using @QueryParam with @POST or @PUT

I'm using jersey API for some REST web services with apache Tomcat. 我正在使用针对apache Tomcat的一些REST Web服务的jersey API。 I need to pass more than one parameter to a method so I decided to use @QueryParam annotation like this : 我需要将多个参数传递给方法,所以我决定使用@QueryParam注释,如下所示:

@GET
@Path("/date")
@Produces(MediaType.APPLICATION_JSON)
public Response getDate(@QueryParam("id") String Id, @QueryParam("inDate") String inDate)
{
...
}

when I call it like this everything works. 当我这样称它时一切正常。 But when I use annotaitions @POST or @PUT instead of @GET then it shows an error: 但是当我使用注释@POST或@PUT而不是@GET时,它会显示错误:

HTTP Status 405 - Method Not Allowed HTTP状态405 - 不允许的方法

message Method Not Allowed 消息方法不允许

description The specified HTTP method is not allowed for the requested resource (Method Not Allowed). description对于请求的资源,不允许使用指定的HTTP方法(Method Not Allowed)。

Is it possible to user this with POST or PUT and how? 是否可以使用POST或PUT进行此操作以及如何使用?

Any help is appreciated. 任何帮助表示赞赏。

Yes, you just need to make the request using POST or PUT. 是的,您只需要使用POST或PUT发出请求。 This can't be done via the URL - you'd need a specific client (for example the http resource firefox plugin) that can send requests with methods other than GET. 这不能通过URL完成 - 您需要一个特定的客户端(例如http资源firefox插件),它可以使用GET以外的方法发送请求。 Note that for POST you can also use @FormParam 请注意,对于POST,您还可以使用@FormParam

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM