restful服务之客户端访问jeysey使用
来源:网络收集 点击: 时间:2024-08-17引入jar包,下载地址maven下载:
http://mvnrepository.com/artifact/com.sun.jersey/jersey-client/1.19.4
大家后续要下载什么jar包,也可以直接按这个地址搜索,查找很方便快捷!
2/4import javax.ws.rs.core.MediaType;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
public class TestClient {
public static void testClient(String uri){
Client client = Client.create();
WebResource webResource = client.resource(uri);
String result = webResource.type(MediaType.APPLICATION_JSON+;charset=utf-8)
.post(String.class);
System.out.println(result);
}
public static void main(String args) {
String uri = http://127.0.0.1:99/hi/payBook/queryPayInfo;
//返回结果:json
//String uri = http://目标地址:99/hi/熊猫人;
//返回结果:json
testClient(uri);
}
}
3/4如果服务端请求需要requestbody,则是
ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_JSON+;charset=+charset)
.post(ClientResponse.class, requestbody_json);
//requestbody_json=json字符串。。。
4/4测试工具,firefox下载RestClient

版权声明:
1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。
2、本站仅提供信息发布平台,不承担相关法律责任。
3、若侵犯您的版权或隐私,请联系本站管理员删除。
4、文章链接:http://www.1haoku.cn/art_1131466.html