public class ToInterface {
/**
* post方式提交表单(模拟用户登录请求)
*/
public static void postForm() {
// 创建默认的httpClient实例.
CloseableHttpClient httpclient = HttpClients.createDefault();
// 创建httppost
HttpPost httppost = new HttpPost("http://localhost:8000/send/sendWechatOrSMS");
// 创建参数队列
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
String string = "{\"userId\":\"0\",\"productType\":\"0\",\"feeName\":\"0\",\"accountType\":\"0\",\"account\":\"0\",\"feeTime\":\"0\",\"send_type\":\"0\",\"ordNo\":\"No201512270001\",\"orderType\":\"儿童口腔就医卡\",\"orderDate\":\"淘宝网\",\"template_code\":\"sl_qy_payment\",\"phone\":\"18618265268\"}";
formparams.add(new BasicNameValuePair("string", string));
UrlEncodedFormEntity uefEntity;
try {
uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
httppost.setEntity(uefEntity);
System.out.println("executing request " + httppost.getURI());
CloseableHttpResponse response = httpclient.execute(httppost);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("--------------------------------------");
System.out.println("Response content: " + EntityUtils.toString(entity, "UTF-8"));
System.out.println("--------------------------------------");
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} public static void main(String[] args) {
postForm();
// interfaceUtil("http://192.168.10.89:8080/eoffice-restful/resources/sys/oadata", "usercode=10012");
// interfaceUtil("http://192.168.10.89:8080/eoffice-restful/resources/sys/oaholiday",
// "floor=first&year=2017&month=9&isLeader=N");
}
}

httpclient方式调用接口的更多相关文章

  1. HttpClient方式调用接口的实例

    使用HttpClient的方式调用接口的实例. public class TestHttpClient { public static void main(String[] args) { // 请求 ...

  2. HttpClient方式调用接口的java 简单案例源码+附jar包

    1 package com.itNoob.httpClient; import org.apache.commons.httpclient.HttpClient; import org.apache. ...

  3. 05 . Vue前端交互,fetch,axios,以asyncawait方式调用接口使用及案例

    目标 /* 1. 说出什么是前后端交互模式 2. 说出Promise的相关概念和用法 3. 使用fetch进行接口调用 4. 使用axios进行接口调用 5. 使用asynnc/await方式调用接口 ...

  4. HttpClient远程调用接口

    详细参考这个博文:http://www.cnblogs.com/itliucheng/p/5065619.html 一.get请求: //关键代码就这几行 String urlNameString = ...

  5. HttpPost方式调用接口的3种方式

    第一种:需要httpclient的依赖包 <dependency> <groupId>org.apache.httpcomponents</groupId> < ...

  6. httpclient 方式提供接口

    在后台写好自己的方法: 打开shiro验证,设置url访问: 提供包调用http方式连接后台获取数据: String url = getUrl(); HttpClient client = new H ...

  7. Postman中使用post方式调用接口

    选择body-row,输入data

  8. HttpClient Get/Post方式调用Http接口

    本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...

  9. java通过HttpClient方式和HttpURLConnection方式调用WebService接口

    1.引入maven依赖: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifac ...

随机推荐

  1. (二)Knockout 文本与外观绑定

    Visible Visible binding会依据绑定的数据来决定相应的DOM元素是否隐藏,hidden或visible. 我们首先在js文件部分定义一个view model,这里我创建的是一个ob ...

  2. 使用 Sonar 检测代码质量

    经历了一段时间的加班赶项目进度之后,今天终于闲下来了.忽然不知道干啥.于是,想着做点什么吧.突然想起了码云上面有个代码分析的功能,用的是 Sonar 于是想来玩玩这个. 一.下载Sonar,和初始化, ...

  3. 用PHPExcel导出导入Excel

    thinkPHP5.0框架 查询数据库调用Excel方法 public function exportlist(){ $orderModel = new OrderModel(); if($start ...

  4. 002 python准备做题的一些准备

    在这里,刷刷题,然后,将比较有用的连接粘贴一下在这里.

  5. Petrozavodsk Summer-2017. Warsaw U Contest

    A. Connectivity 设$f[i][j]$为第$i$张图中$j$点所在连通块的编号,加边时可以通过启发式合并在$O(dn\log n)$的时间内维护出来. 对于每个点,设$h[i]$为$f[ ...

  6. TypeScript系列 - 什么是TypeScript

    看了很多关于TypeScript的文章,总体说来没有很好的,一个系统的学习TypeScript的资源. 接下来,我将给大家带来TypeScript的系列,让你和我一样,一步一步的学习TypeScrip ...

  7. swust oj 972

    统计利用先序遍历创建的二叉树的宽度 1000(ms) 10000(kb) 2938 / 6810 利用先序递归遍历算法创建二叉树并计算该二叉树的宽度.先序递归遍历建立二叉树的方法为:按照先序递归遍历的 ...

  8. 微信小程序wx.showLoading

    效果图: 代码: wx.showLoading({ title: '加载中...', }) wx.request({ url: '', success(res){}, fail(){}, comple ...

  9. 【Python基础】lpthw - Exercise 37 复习各种符号

    本节需要熟悉python的符号和关键字的功能. 一.关键字 1. and 逻辑与,如 True and False == False的值为True 2. as with...as...的功能类似try ...

  10. boot跳转到app后,中断不起作用的原因

    boot跳转到app后 osKernelStart()之前,中断有问题,不起作用 原因是因为boot跳转之前__disable_irq(); 跳转到APP后,并不是一切从头开始,__disable_i ...