【问题标题】:Simple POST request to Java Web Service对 Java Web 服务的简单 POST 请求
【发布时间】:2013-04-19 22:09:48
【问题描述】:

我用 Java 创建了一个 RestfulWeb 服务,它可以很好地处理 GET 请求。但是我找不到一些关于如何让它接受 POST 请求的好资源。

这就是我运行 GET 的方式

@Path("/hello")
public class Hello {

    @GET
    @Path(value = "/ids/{id}")
    public String ids(@PathParam(value = "id") final String id) throws JSONException {
        return getResults("select * from " + id);
    }

为了从 Web 访问此方法,我只需访问 mywebservice.com/hello/thisismyID,该方法就会收到“ID”。

如果使用 POST 来完成,会是什么样子。

提前致谢,

-D

【问题讨论】:

标签: java web-services post


【解决方案1】:

例子

@Path("/hello")
public class Hello {

    @POST
    @Path(value = "/ids")
    public String ids(@HeaderParam("id") final String id) throws JSONException {
        return getResults("select * from " + id);
    }
}

【讨论】:

  • @MariuszS 你能分享一下如何调用该邮政服务的网址吗?
  • @Sateesh2607 类似curl -X POST -H "id=foo" http://localhost:8080/hello/ids
【解决方案2】:
@Path("/hello")
public class Hello {

    @POST
    @Path("/ids/{id}")
    public String ids(@PathParam("id") final String id) throws JSONException {
        return getResults("select * from " + id);
    }
}

可以在此处找到详尽的教程:Vogella_REST

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-27
  • 2014-11-03
  • 1970-01-01
相关资源
最近更新 更多