Posted on 2010-08-12 19:52 
疯狂 阅读(1620) 
评论(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");
    
   }