HttpClient方式调用接口的实例
2017-11-08 08:36
459 查看
1 public class TestHttpClient { 2 3 public static void main(String[] args) { 4 // 请求接口地址 5 String url = ""; 6 // 请求参数 7 String userid = ""; 8 9 HttpClient httpclient = null; 10 PostMethod post = null; 11 try { 12 //创建连接 13 httpclient = new HttpClient(); 14 post = new PostMethod(url); 15 // 设置编码方式 16 post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); 17 // 添加参数 18 post.addParameter("userid", userid); 19 // 执行请求 20 httpclient.executeMethod(post); 21 // 接口返回信息 22 String info = new String(post.getResponseBody(), "UTF-8"); 23 System.out.println(info); 24 } catch (Exception e) { 25 e.printStackTrace(); 26 } finally { 27 // 关闭连接,释放资源 28 post.releaseConnection(); 29 ((SimpleHttpConnectionManager) httpclient.getHttpConnectionManager()).shutdown(); 30 } 31 } 32 }
相关文章推荐
- HttpClient方式调用接口的实例
- 微信小程序 wx.request(接口调用方式)详解及实例
- 使用httpclient实现http接口调用实例
- 使用httpclient实现http接口调用实例
- 使用HttpClient调用接口的实例讲解
- 《转》使用httpclient实现http接口调用实例
- Java WebService 简单实例 方式三(axis1接口调用方式)
- 使用httpclient实现http接口调用实例
- 使用httpclient实现http接口调用实例
- 使用httpclient实现http接口调用实例
- C#接口的隐式和显示调用,区别和实例
- WebApi系列~通过HttpClient来调用Web Api接口~续~实体参数的传递
- PHP用户管理中常用接口调用实例及解析(含源码)
- httpclient接口调用
- PHP 开发 APP 接口 学习笔记与总结 - APP 接口实例 [4] 首页 APP 接口开发方案 ③ 定时读取缓存方式
- 2018/01/08JAVA 基础 / 接口与继承:调用父类/子类的类方法、对象方法,访问父类的类属性、对象属性的方式汇总
- Python接口(3):Python实例浅谈之三Python与C/C++相互调用
- 浅谈java调用Restful API接口的方式
- java调用webservice WSDL形式接口之apache axis方式调用(一)
- Java调用哈工大LTP接口(JNI方式实现)