/**
* httpcomponents-client-4.3.6
* @author y
*/
public class HttpUtil { public static String httpPost( List<NameValuePair> formparams,final String url){
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8); //设置网络超时
RequestConfig config = RequestConfig.custom()
.setConnectionRequestTimeout(3*1000)
.setConnectTimeout(3*1000)
.setSocketTimeout(3*1000)
.build(); HttpPost httppost = new HttpPost(url);
httppost.setConfig(config);
httppost.setEntity(entity); CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null; String reuslt = ""; try {
response = httpclient.execute(httppost); if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entityContent = response.getEntity();
if (entityContent != null) {
reuslt = EntityUtils.toString(entityContent, Consts.UTF_8); //指定编码格式防止中文乱码
}
}else{
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, "网络链接超时");
}
} catch (IOException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}finally {
try{
if(response!=null){
response.close();
}
}catch (IOException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}
} return reuslt;
} }

httpcomponents-client-4.3.6 HttpPost的简单使用的更多相关文章

  1. Apache HttpComponents Client 4.0快速入门/升级-2.POST方法访问网页

    Apache HttpComponents Client 4.0已经发布多时,httpclient项目从commons子项目挪到了HttpComponents子项目下,httpclient3.1和 h ...

  2. JAVA中使用Apache HttpComponents Client的进行GET/POST请求使用案例

    一.简述需求 平时我们需要在JAVA中进行GET.POST.PUT.DELETE等请求时,使用第三方jar包会比较简单.常用的工具包有: 1.https://github.com/kevinsawic ...

  3. client高性能组件化框架React简单介绍、特点、环境搭建及经常使用语法

    [本文源址:http://blog.csdn.net/q1056843325/article/details/54729657 转载请加入该地址] 明天就是除夕了 预祝大家新春快乐 [ ]~( ̄▽ ̄) ...

  4. HttpComponents入门解析

    1 简介 超文本传输协议(http)是目前互联网上极其普遍的传输协议,它为构建功能丰富,绚丽多彩的网页提供了强大的支持.构建一个网站,通常无需直接操作http协议,目前流行的WEB框架已经透明的将这些 ...

  5. HttpComponents了解

    原文地址:http://blog.csdn.net/jdluojing/article/details/7300428 1 简介 超文本传输协议(http)是目前互联网上极其普遍的传输协议,它为构建功 ...

  6. java使用httpcomponents 上传文件

    一.httpcomponents简介 httpcomponents 是apache下的用来负责创建和维护一个工具集的低水平Java组件集中在HTTP和相关协议的工程.我们可以用它在代码中直接发送htt ...

  7. HttpComponents 也就是以前的httpclient项目

    HttpComponents 也就是以前的httpclient项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端/服务器编程工具包,并且它支持 HTTP 协议最新的版本和建议.不 ...

  8. golang使用http client发起get和post请求示例

    [转自 http://www.01happy.com/golang-http-client-get-and-post/ ] get请求 get请求可以直接http.Get方法,非常简单. 1 2 3 ...

  9. 简单粗暴套娃模式组json发送https请求

    各位童鞋大家好,向来简单粗暴的铁柱兄给大家来玩一手套娃模式来组Json数据,不说别的,无脑套. 当然,这一手比较适合临场用一下,若长期用的话建议搞一套适用的框架,只管set就好了.话不多说开始上课. ...

随机推荐

  1. 自制单片机之七……RS232串口

    在我的板子上其它的部分都已完成了,现在就剩下RS232串口了.串口对于单片机很重要,有了它就可以和PC通信了,可以用PC来控制你的单片机,也可以将你单片机上采集的数据传到PC上. 留的位置好像有点挤. ...

  2. STLtoSVG,and SVG to Bmp

    先用这两个工具: Slic3R或者Skeinforge:这个两个工具的作用就是把STL文件切片为叠加的矢量图(SVG格式) 因为SVG是分层的,一层一层的把每层都转换成一张Bmp文件 听说ImageM ...

  3. wifidog auth-server安装配置

  4. 页面onclick()中传值问题

    html中onclick()里面传变量到javascript中的问题,小小的记录下: 传变量的话一定要加  '' <span onclick="sellGoods('${session ...

  5. 查看syslog-ng内存,兼容容器情况

    syslog_pid=`ps -ef|grep syslog-ng|grep -v grep |awk '{print $2}'` pid_count=`ps -ef|grep syslog-ng|g ...

  6. javascript对URL中的参数进行简单加密处理

    javascript的api本来就支持Base64,因此我们可以很方便的来进行编码和解码. var encodeData = window.btoa("name=xiaoming&a ...

  7. #爬虫必备,解析html文档----beautifulsoup的简单用法

    #出处:http://mp.weixin.qq.com/s?__biz=MjM5NzU0MzU0Nw==&mid=201820961&idx=2&sn=b729466f334d ...

  8. iphone UIScrollView缩放

    allImageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; allImageScrol ...

  9. [Angular 2] Using ng-for to repeat template elements

    This lesson covers Angular 2’s version of looping through data in your templates: ng-for. It’s conce ...

  10. Easyui 排序时 自动向后排传sort order 你妹真坑爹

    request 的时候 发现 sort 竟然是个数组!