---
title: "HttpClient4.4.1 post提交xml"
author: "lanfei"
date: "2015-05-08T17:26:59Z"
tags: []
categories: ["编程语言"]
slug: "httpclient4-4-1-post-xml"
draft: false
lastmod: "2015-05-08T17:26:59Z"
id: 2209501
url: "https://lanfei.iteye.com/blog/2209501"
---

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