疯狂

STANDING ON THE SHOULDERS OF GIANTS
posts - 481, comments - 486, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

httpclient 简单例子

Posted on 2010-08-12 19:52 疯狂 阅读(1593) 评论(1)  编辑  收藏 所属分类: java web
public void doPost(String xml) throws UnsupportedEncodingException{
 
  HttpClient httpclient = new DefaultHttpClient();
  HttpContext localContext = new BasicHttpContext();
  
  List<NameValuePair> qparams = new ArrayList<NameValuePair>();
  qparams.add(new BasicNameValuePair("xmldata", xml));
  HttpPost httppost = new HttpPost(“http://......”);
  httppost.setEntity(new UrlEncodedFormEntity(qparams, HTTP.UTF_8));
  HttpResponse response = null;
  try {
   response = httpclient.execute(httppost, localContext);
   BufferedReader stream = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
   String l ="";
   while ((l=stream.readLine())!=null) {
    System.out.println(l);
   }
  } catch (Exception e) {
   logger.error(e.getMessage());
  }
  httpclient.getConnectionManager().shutdown();
 }
   public final static void main(String[] args) throws Exception {
   
    new HttpClientService().doPost("dopost");
   
   }

评论

# re: httpclient 简单例子  回复  更多评论   

2014-01-07 14:55 by 地方
简单例子

只有注册用户登录后才能发表评论。


网站导航: