ITeye博客

HttpClient4.4.1 post提交xml

lanfei · 2015-05-08 17:26 · java · 编程语言 · Markdown

	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;
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。