post方法发送较大的数据.
public class HttpClientUtil {
private HttpClient client;
private HttpPost post;
private HttpGet get;
private HttpResponse response;
public HttpClientUtil() {
super();
if (StringUtils.isNotBlank(GlobalParams.PROXY_IP)) {
client = new DefaultHttpClient();
HttpHost host = new HttpHost(GlobalParams.PROXY_IP, GlobalParams.PROXY_PORT);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
}
}
public InputStream sendXml(String xml, String uri) {
post = new HttpPost(uri);
StringEntity entity;
try {
entity = new StringEntity(xml, ConstantValue.ENCODING);
post.setEntity(entity);
response = client.execute(post);
if (response.getStatusLine().getStatusCode()==200){
return response.getEntity().getContent();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}