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 接口调用的更多相关文章

  1. WebApi系列~通过HttpClient来调用Web Api接口

    回到目录 HttpClient是一个被封装好的类,主要用于Http的通讯,它在.net,java,oc中都有被实现,当然,我只会.net,所以,只讲.net中的HttpClient去调用Web Api ...

  2. bugzilla4的xmlrpc接口api调用实现分享: xmlrpc + https + cookies + httpclient +bugzilla + java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能

    xmlrpc .  https . cookies . httpclient.bugzilla . java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能,网上针对bugzilla的实现很 ...

  3. So easy Webservice 3.使用HttpClient工具调用Webservice接口

    首先,看看webservice服务调用演示: a) 登录http://www.webxml.com.cn b) 单击手机查询服务 c) 选择要调用的方法 例如: getMobileCodeInfo 输 ...

  4. 通过HttpClient来调用Web Api接口

    回到目录 HttpClient是一个被封装好的类,主要用于Http的通讯,它在.net,java,oc中都有被实现,当然,我只会.net,所以,只讲.net中的HttpClient去调用Web Api ...

  5. Http下的各种操作类.WebApi系列~通过HttpClient来调用Web Api接口

    1.WebApi系列~通过HttpClient来调用Web Api接口 http://www.cnblogs.com/lori/p/4045413.html HttpClient使用详解(java版本 ...

  6. httpclient,java跨系统调用,第三接口调用实例

    java跨系统调用,第三方接口调用,有三种方式 1:rmi/rpc 传序列化对象 2:webservice 传xml 3:restful 传json 接下来给大家演示怎么用httpclient调用re ...

  7. http请求,HttpClient,调用短信接口

    项目中安全设置找回密码的功能,需要通过发送短信验证绑定手机,通过绑定的手机号验证并重新设置密码. 因为项目是通过maven管理的,所以需要在pom.xml文件中引入jar包, maven引入的jar包 ...

  8. HttpClient远程接口调用-实名认证

    1.HttpClient远程接口调用 1)用户注册 注册按钮button提交表单时,要return false form表单 <!-- action="http://localhost ...

  9. HttpClient 远程接口调用方式

    远程接口调用方式HttpClient 问题:现在我们已经开发好了接口了,那该如何调用这个接口呢? 答:使用Httpclient客户端.   Httpclient简介 什么是httpclient Htt ...

随机推荐

  1. SPOJ:Help BTW(二分)

    BTW wants to buy a gift for her BF and plans to buy an integer array. Generally Integer arrays are c ...

  2. BZOJ_2017_[Usaco2009 Nov]硬币游戏_博弈论+DP

    BZOJ_2017_[Usaco2009 Nov]硬币游戏_博弈论+DP Description 农夫约翰的奶牛喜欢玩硬币游戏,因此他发明了一种称为“Xoinc”的两人硬币游戏. 初始时,一个有N(5 ...

  3. You can't specify target table 'xxx' for update in FROM clause

    1.执行sql语句报上面的错误: DELETE FROM db_student WHERE RowGuid IN ( SELECT RowGuid FROM db_student WHERE age ...

  4. ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 06. Controller 返回View

    Controller父类会提供很多上下文的相关信息,还提供了很多封装的方法 返回的对象要求实现了IActionResult接口 继承父类,并引入命名空间 写this点就出现很多东西,这些就是上下文的信 ...

  5. SCUT - 249 - A piece of Cake - 组合数学

    https://scut.online/contest/25/I 由结论:d维物体切n刀分成的部分=sum(C(n,0)~C(n,d)),直接算就行了.

  6. css margin边界叠加问题详谈

    问题:给子元素一个margin-top值,其父元素会跟着往下走margin-top的值 一.代码展示 HTML <body> <div class="box"&g ...

  7. hdoj5667 BestCoder Round #80 【费马小定理(膜拜)+矩阵快速幂+快速幂】

    #include<cstdio> #include<string> #include<iostream> #include<vector> #inclu ...

  8. Log2Net组件代码详解(附开源代码)

    上一篇,我们介绍了Log2Net的需求和整体框架,我们接下来介绍我们是如何用代码实现Log2Net组件的功能的. 一.整体介绍 Log2Net组件本身是一个Dll,供其他系统调用. 本部分由以下几部分 ...

  9. PJzhang:lijiejie的敏感目录爆破工具BBScan

    猫宁!!! 参考链接: https://www.freebuf.com/sectool/85729.html https://segmentfault.com/a/1190000014539449 这 ...

  10. jsp 接收汉字参数乱码

    这两天跟汉字问题较上劲了,真是考验基本功 1.  ${param.userName} 乱码 解决方法: <%String name = (String)request.getParameter( ...