`
lanfei
  • 浏览: 150291 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

HttpClient4.4.1 post提交xml

    博客分类:
  • java
 
阅读更多
	public static String sendXMLDataByPost( String url,String xmlData) throws ClientProtocolException, IOException {
	  
	  Integer statusCode = -1;
	  if (httpClient == null) {
		  httpClient = new DefaultHttpClient();
	  }
	  HttpPost post = new HttpPost(url);
	  StringEntity entity = new StringEntity(xmlData);
	  post.setEntity(entity);
	  post.setHeader("Content-Type", "text/xml;charset=UTF-8");
	  HttpResponse response = httpClient.execute(post);
	  statusCode = response.getStatusLine().getStatusCode();
	  System.out.println("返回状态:"+statusCode);
	  // 获取返回数据  
      HttpEntity repEntity = response.getEntity(); 
      String body = EntityUtils.toString(repEntity,"UTF-8");  
	  return body;
	}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics