簡體   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