支持POST,GET,DELETE,PUT代码如下:
public static void post() throws Throwable {
RestClient client = new RestClient();
Resource resource = client.resource("http://api.linkrmb.com/app/api");
ClientResponse clientResponse=resource.post("id=123&name=456");
System.out.println(clientResponse.getStatusCode());
}
public static void put() throws Throwable {
RestClient client = new RestClient();
Resource resource = client.resource("http://api.linkrmb.com/app/api");
Item item=new Item();
item.setId("id");
item.setName("name");
resource.accept(MediaType.APPLICATION_JSON_TYPE).contentType(MediaType.APPLICATION_JSON_TYPE);
ClientResponse clientResponse= resource.put(JSON.toJSONString(item));
System.out.println(clientResponse.getStatusCode());
}
public static void delete() throws Throwable {
RestClient client = new RestClient();
Resource resource = client
.resource("http://api.linkrmb.com/app/api/123");
ClientResponse clientResponse=resource.delete();
System.out.println(clientResponse.getStatusCode());
}
public static void get() throws Throwable {
RestClient client = new RestClient();
Resource resource = client
.resource("http://api.linkrmb.com/app/api/123");
ClientResponse clientResponse=resource.get();
System.out.println(clientResponse.getStatusCode());
System.out.println(clientResponse.getEntity(String.class));
}
依赖的lib如下:
<dependency> <groupId>org.apache.wink</groupId> <artifactId>wink-client</artifactId> <version>1.4</version> </dependency>