Apache HttpClient实现访问RESTFUL接口
来源:互联网 发布:电玩巴士有几家淘宝店 编辑:程序博客网 时间:2024/06/18 15:47
1、添加jar
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
2、代码
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://172.18.1.177:8080/declare-rest/restful/company/getPaging?currentPage=1&pageRecord=2");
CloseableHttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpGet);
System.out.print("Protocol Version :: ");
System.out.println(httpResponse.getProtocolVersion());
System.out.println("--------------------------------------------------");
System.out.print("Status Code :: ");
System.out.println(httpResponse.getStatusLine().getStatusCode());
System.out.println("--------------------------------------------------");
System.out.print("Reason Phrase :: ");
System.out.println(httpResponse.getStatusLine().getReasonPhrase());
System.out.println("--------------------------------------------------");
System.out.print("Status Line :: ");
System.out.println(httpResponse.getStatusLine().toString());
System.out.println("--------------------------------------------------");
HttpEntity httpEntity = httpResponse.getEntity();
System.out.print("Content Length :: ");
System.out.println(httpEntity.getContentLength());
System.out.println("--------------------------------------------------");
System.out.print("Content Type :: ");
System.out.println(httpEntity.getContentType());
System.out.println("--------------------------------------------------");
System.out.print("Content :: ");
System.out.println(httpEntity.getContent());
System.out.println("--------------------------------------------------");
System.out.print("Content Text :: ");
System.out.println(EntityUtils.toString(httpEntity));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpClient.close();
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
- Apache HttpClient实现访问RESTFUL接口
- httpclient访问restful
- Apache HttpClient 实现 Java 调用 Http 接口
- 使用Apache Httpclient访问Spring rest接口下载文件
- Restful接口访问工具
- httpclient访问接口
- RESTful Java client with Apache HttpClient
- 配置restful接口https访问
- Spring RestTemplate 访问 restFul 接口
- springmvc 实现restful接口
- Restful接口实现方法
- Restful接口实现实例
- httpclient提交表单 访问接口
- HttpClient 实现https访问
- android利用httpclient实现post、get请求restful接口进行json和form表单数据提交等公共方法类
- Apache HttpClient调用Spring3 MVC Restful Web API演示
- restful接口ADF实现代码
- springMVC的Restful接口实现
- ES6/ES2015常用知识点和概念
- 泛型定义和使用
- laravel model relationship
- background-image 和 img
- javascript使用web proxy来实现ajax cross-domain通信
- Apache HttpClient实现访问RESTFUL接口
- how browser works
- javascript requestAnimationFrame vs. setTimeout
- Vertical-Align: 关于inline,inline-block文本排版
- Spring的#和$的区别?
- Android多线程之IntentService
- 常用sql commands以及mysql问题解决日志
- sql join实例图解
- escape,encodeURI,encodeURIComponent, URLEncode, RawURLEncode, HTMLEntity, AddSlash, JSON Encode