HttpClient 接口调用
String url = "http://127.0.0.1:8080/api";
//然后根据表名获取公司信息
HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("comName", comName));
HttpResponse httpResponse = null;
HttpEntity httpEntity = null;
try {
//设置超时时间 httpclient4.5之后改为构建requestConfig对象
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000).setConnectionRequestTimeout(1000)
.setSocketTimeout(5000).build();
httppost.setConfig(requestConfig);
HttpClient httpclient = HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
httppost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = httpclient.execute(httppost);
httpEntity = httpResponse.getEntity();
} catch (UnsupportedEncodingException e1) {
logger.error(e1.getMessage());
} catch (ClientProtocolException e1) {
logger.error(e1.getMessage());
} catch (IOException e1) {
logger.error(e1.getMessage());
}
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {// 请求正常
try {
String result = EntityUtils.toString(httpEntity);
JSONObject data = JSONObject.fromObject(httpEntity);
if("200".equals(data.get("code"))){
System.out.println("调用成功");
}else{
logger.error(data.get("message"));
}
} catch (Exception e) {
logger.error(e.getMessage());
}
}else {
try {
logger.error(EntityUtils.toString(httpEntity));
} catch (ParseException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}
}
HttpClient 接口调用的更多相关文章
- WebApi系列~通过HttpClient来调用Web Api接口
回到目录 HttpClient是一个被封装好的类,主要用于Http的通讯,它在.net,java,oc中都有被实现,当然,我只会.net,所以,只讲.net中的HttpClient去调用Web Api ...
- bugzilla4的xmlrpc接口api调用实现分享: xmlrpc + https + cookies + httpclient +bugzilla + java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能
xmlrpc . https . cookies . httpclient.bugzilla . java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能,网上针对bugzilla的实现很 ...
- So easy Webservice 3.使用HttpClient工具调用Webservice接口
首先,看看webservice服务调用演示: a) 登录http://www.webxml.com.cn b) 单击手机查询服务 c) 选择要调用的方法 例如: getMobileCodeInfo 输 ...
- 通过HttpClient来调用Web Api接口
回到目录 HttpClient是一个被封装好的类,主要用于Http的通讯,它在.net,java,oc中都有被实现,当然,我只会.net,所以,只讲.net中的HttpClient去调用Web Api ...
- Http下的各种操作类.WebApi系列~通过HttpClient来调用Web Api接口
1.WebApi系列~通过HttpClient来调用Web Api接口 http://www.cnblogs.com/lori/p/4045413.html HttpClient使用详解(java版本 ...
- httpclient,java跨系统调用,第三接口调用实例
java跨系统调用,第三方接口调用,有三种方式 1:rmi/rpc 传序列化对象 2:webservice 传xml 3:restful 传json 接下来给大家演示怎么用httpclient调用re ...
- http请求,HttpClient,调用短信接口
项目中安全设置找回密码的功能,需要通过发送短信验证绑定手机,通过绑定的手机号验证并重新设置密码. 因为项目是通过maven管理的,所以需要在pom.xml文件中引入jar包, maven引入的jar包 ...
- HttpClient远程接口调用-实名认证
1.HttpClient远程接口调用 1)用户注册 注册按钮button提交表单时,要return false form表单 <!-- action="http://localhost ...
- HttpClient 远程接口调用方式
远程接口调用方式HttpClient 问题:现在我们已经开发好了接口了,那该如何调用这个接口呢? 答:使用Httpclient客户端. Httpclient简介 什么是httpclient Htt ...
随机推荐
- UVA-11078(水题)
题意: 给一个序列,找两个整数a[i],a[j]使得a[i]-a[j]最大; 思路: 从前往后扫一遍;水题; AC代码: #include <bits/stdc++.h> /* #incl ...
- BZOJ_3963_[WF2011]MachineWorks_斜率优化+CDQ分治
BZOJ_3963_[WF2011]MachineWorks_斜率优化+CDQ分治 Description 你是任意性复杂机器公司(Arbitrarily Complex Machines, ACM) ...
- Allure生成测试报告
Allure 使用 安装 adapter 如果要在 pytest 中使用 Allure,需要使用一个 Adaptor Allure Pytest Adaptor 安装 pytest-allure-ad ...
- .NETFramework:Stream
ylbtech-.NETFramework:Stream 1.返回顶部 1. #region 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, Publi ...
- js 模拟a标签打开新网页
在这里备份一下,方便以后查找. var el = document.createElement("a"); document.body.appendChild(el); e ...
- k8s认证及ServiceAccount-十五
一.ServiceAccount (1)简介 https://www.kubernetes.org.cn/service-account Service account是为了方便Pod里面的进程调用K ...
- E20170509-hm
slice vt. 切成片; 切下; 划分; n. 薄片,切片 slicing n. 切割; 限幅,限制; inspect v. 视察; 检查 inspector n. 检查员; (英 ...
- C++章节练习题
笔试宝典:http://www.bishibaodian.com/writtenCircle/lightquestionlist http://www.bishibaodian.com/written ...
- IT兄弟连 JavaWeb教程 Servlet表单乱码问题
在使用原生的Servlet进行Web应用开发时经常会遇到一些中文乱码问题,造成乱码问题的原因只有一个:即客户端与服务端的字符编码不一致所导致的. 请求参数乱码问题 服务器端获取客户端传递过来的数据出现 ...
- postman接口测试系列: 时间戳和加密
在使用postman进行接口测试的时候,对于有些接口字段需要时间戳加密,这个时候我们就遇到2个问题,其一是接口中的时间戳如何得到?其二就是对于现在常用的md5加密操作如何在postman中使用代码实现 ...