wink之rest full client使用

本文提供了使用Java和Wink客户端库实现RESTful API调用的示例代码,包括POST、GET、DELETE和PUT请求的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

支持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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值