开发者

Call POST method in RESTFul Web service

I want to create a sam开发者_如何转开发ple RESTful web service in java which involves all the four CRUD operations and I deployed it in tomcat. I used JAX-RS (Jersey) library to implement this in java. As of now , I can call the GET method to retrieve the list of records and display it. But I don know how to call the POST, PUT and DELETE method. Can anyone tell how to call those methods ?


Give this a shot, you can extract the key/value pairs on the server side pretty easily:

ClientConfig config = new DefaultClientConfig();
com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(config);

MultiValueMap formData = new MultiValueMapImpl();
formData.add("key", "value");

WebResource resource = client.resource("http://path/to/resource");
ClientResponse response = resource.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜