package com.ithm.lottery16.net;
import java.io.InputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import com.ithm.lottery16.ConstantValue;
import com.ithm.lottery16.GloableParams;
public class HttpClientAdapter {
private HttpClient client;
private HttpRequest request;
private HttpGet get;
private HttpPost post;
private HttpResponse response;
public HttpClientAdapter()
{
client=new DefaultHttpClient();
if(StringUtils.isNotBlank(GloableParams.PROXY_IP))
{
//wap方式
HttpHost host=new HttpHost(GloableParams.PROXY_IP, GloableParams.PROXY_PORT);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
}
}
public InputStream sendXml(String url, String xml) {
post = new HttpPost(url);
StringEntity entity;
try {
entity = new StringEntity(xml, ConstantValue.CHARSET);
post.setEntity(entity);
response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
return response.getEntity().getContent();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}