繁体   English   中英

调用Web服务的Post方法

[英]Calling a Post method of a webservice

我有3个端点的Web服务。 如下 -

GET     /Game/getGameAll/ (com.service.rest.Game)
GET     /Game/getGameById/{gameId} (com.service.rest.Game)
POST    /Game/updateGame/{gameId}/{isAvailable} (com.service.rest.Game)

为了测试,我使用-

localhost:8080/Game/getGameAll/
localhost:8080/Game/getGameById/1000

而且效果很好。

但是在执行更新功能时-

localhost:8080/Game/updateGame/1000/true

它给我一个错误404:方法未找到。

但是,如果我将注释从post更改为get。 它执行。

//@POST  : If this is changed to Get, it works! But not with @POST. 
@GET
@Path(value = "/updateGame/{gameId}/{isAvailable}")
@Produces(MediaType.APPLICATION_JSON)
public Game updateGame(
    @PathParam(value = "gameId") Integer gameId,
    @PathParam(value = "isAvailable") int isAvailable) { .. 
.
}

如何执行Web服务的Post方法?

您是否正在通过网络浏览器尝试此操作? 您将无法以这种方式调用POST方法。

您可以从命令行使用curl ,也可以使用诸如Postman之类的交互式客户端。

暂无
暂无

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

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