httpclient方式调用接口
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方式调用接口的更多相关文章
- HttpClient方式调用接口的实例
使用HttpClient的方式调用接口的实例. public class TestHttpClient { public static void main(String[] args) { // 请求 ...
- HttpClient方式调用接口的java 简单案例源码+附jar包
1 package com.itNoob.httpClient; import org.apache.commons.httpclient.HttpClient; import org.apache. ...
- 05 . Vue前端交互,fetch,axios,以asyncawait方式调用接口使用及案例
目标 /* 1. 说出什么是前后端交互模式 2. 说出Promise的相关概念和用法 3. 使用fetch进行接口调用 4. 使用axios进行接口调用 5. 使用asynnc/await方式调用接口 ...
- HttpClient远程调用接口
详细参考这个博文:http://www.cnblogs.com/itliucheng/p/5065619.html 一.get请求: //关键代码就这几行 String urlNameString = ...
- HttpPost方式调用接口的3种方式
第一种:需要httpclient的依赖包 <dependency> <groupId>org.apache.httpcomponents</groupId> < ...
- httpclient 方式提供接口
在后台写好自己的方法: 打开shiro验证,设置url访问: 提供包调用http方式连接后台获取数据: String url = getUrl(); HttpClient client = new H ...
- Postman中使用post方式调用接口
选择body-row,输入data
- HttpClient Get/Post方式调用Http接口
本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...
- java通过HttpClient方式和HttpURLConnection方式调用WebService接口
1.引入maven依赖: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifac ...
随机推荐
- Java桥接模式
定义:将抽象部分与它的具体实现部分分离,使他们都可以独立的变化 通过组合的方式建立两个类之间联系,而不是继承 类型:结构型 适用场景: 抽象和具体实现之间增加更多的灵活性 一个类存在两个(或多个)独立 ...
- (七)Knockout 创建自定义绑定
创建自定义绑定 你可以创建自己的自定义绑定 – 没有必要非要使用内嵌的绑定(像click,value等).你可以你封装复杂的逻辑或行为,自定义很容易使用和重用的绑定.例如,你可以在form表单里自定义 ...
- spring Boot异步操作报错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.self.spring.springboot.Jeep' available
我也是最近开始学习Spring Boot,在执行异步操作的时候总是汇报如下的错误: Exception in thread "main" org.springframework.b ...
- 如何导出chrome已安装的拓展程序
如何导出chrome已安装的拓展程序 已安装的chrome插件可以在浏览区中输入*chrome://extensions*便可以查看插件列表. 对于windows系统来说,这些插件对应的目录为: C: ...
- numpy array分割-【老鱼学numpy】
有合并,就有分割. 本节主要讲述如何通过numpy对数组进行横向/纵向分割. 横向/纵向分割数组 首先创建一个6行4列的数组,然后我们对此数组按照横向进行切割,分成3块,这样每块应该有2行,见例子: ...
- Codeforces 513D2 Constrained Tree
Constrained Tree 没写出来好菜啊啊. 首先根据输入我们能算出某些节点的左儿子的范围, 右儿子的范围(此时并不准确) 然后我们在划分u这个节点的时候我们从左右开始用树状数组check每一 ...
- Hadoop| YARN| 计数器| 压缩| 调优
1. 计数器应用 2. 数据清洗(ETL) 在运行核心业务MapReduce程序之前,往往要先对数据进行清洗,清理掉不符合用户要求的数据.清理的过程往往只需要运行Mapper程序,不需要运行Reduc ...
- BZOJ.4598.[SDOI2016]模式字符串(点分治 Hash)
LOJ BZOJ 洛谷 点分治.考虑如何计算过\(rt\)的答案. 记\(pre[i]\)表示(之前的)子树内循环匹配了\(S\)的前缀\(i\)的路径有多少,\(suf[i]\)表示(之前的)子树内 ...
- SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...
- python实现的跳点寻路算法(JPS)
原理参考论文 代码已提交到git(https://github.com/YYRise/find_path/blob/master/jps.py)