Http Post get
来源:互联网 发布:c语言产生1-10随机数 编辑:程序博客网 时间:2024/06/06 10:07
package com.npnets.thread;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.methods.PostMethod;import org.apache.commons.httpclient.methods.RequestEntity;import org.apache.commons.httpclient.methods.StringRequestEntity;import org.apache.log4j.Logger;/** * 这个类已经被取代了 * 2015-8-7 * @author Mr.zhang * */public class SendMessThread extends Thread { private static Logger log = Logger.getLogger(SendMessThread.class); private String msg; private String posturl; public SendMessThread(String msg, String posturl) { this.msg = msg; this.posturl = posturl; } public void run(){ PostMethod method = null; HttpClient client = null; try { client = new HttpClient(); //请求超时 client.getHttpConnectionManager().getParams().setConnectionTimeout(6000); String url = posturl; log.info("Post url:"+url); method = new PostMethod(url); RequestEntity requestEntity = new StringRequestEntity(msg); log.info("Post Message:"+msg); method.setRequestEntity(requestEntity); client.executeMethod(method); InputStream stream = method.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader(stream,"UTF-8")); StringBuffer buf = new StringBuffer(); String line = ""; while(null!=(line=br.readLine())){ buf.append(line).append("\n"); } log.info("response buff : "+buf); } catch (Exception e) { e.printStackTrace(); }finally{ log.info("Http StatusCode:"+method.getStatusCode()); log.info("准备释放连接!!"); method.releaseConnection();//释放连接 client.getHttpConnectionManager().closeIdleConnections(0); log.info("释放连接成功!!"); //第一种 //client.getHttpConnectionManager().closeIdleConnections(0); //第二种 //HttpClient client2 = new HttpClient(new HttpClientParams(),new SimpleHttpConnectionManager(true) ); //方法三 服务器端设置 //method.setRequestHeader("Connection", "close"); } }}
0 0
- Get/Post in http
- http get post head
- http GET POST头
- Http Get Post 区别
- HTTP POST GET详解
- SOAP & HTTP-GET/POST
- Http方法 GET/POST
- HTTP POST GET
- android http post get
- http get post
- HTTP POST GET详解
- http get post
- http get post
- http post 和 get
- Http Get & Post总结
- Android HTTP GET/POST
- http get 和 post
- http get post限制
- android 动态广播与静态广播区别
- 自定义toast外形,多次点击不会总是弹出toast
- Knockout应用开发指南 第四章:模板绑定
- CSS权重的问题:选择器权重值的计算
- php和bom头的冤仇 和 如何在linux下使用命令去掉bom头
- Http Post get
- 游戏AI - 行为树Part2:框架
- 如何使用 Dojo EnhancedGrid 控件进行数据异步保存
- C++ 用libcurl库进行http通讯网络编程
- 部分真题整理5
- Knockout应用开发指南 第五章:创建自定义绑定
- hibernate缓存
- NOIP2011 聪明的质检员
- Firefox 设置成不显示图片