/**
 * HTTP调用处理类
 * 
 * @author lj * 
 */
public class HTTPClient
{
private static final HTTPClient instance = new HTTPClient(); public static final HTTPClient getInstance()
{
return instance;
} private HTTPClient()
{
} /**
 * http协议的处理操作
 * 
 * @param input 输入的参数为请求流
 * 
 * @param httpurl 请求的url
 * @return [参数说明]
 * 
 * @return InputStream [返回的一个流]
 * @exception throws
 */
public InputStream excuteHTTP(InputStream input, String httpurl) throws Exception
{
PostMethod postMethod = new PostMethod(httpurl);
postMethod.setRequestHeader("Connection", "close");
RequestEntity requestEntity = new InputStreamRequestEntity(input, "text/xml; charset=UTF-8");
postMethod.setRequestEntity(requestEntity); HttpClient httpclient = new HttpClient();
InputStream retStream = null; httpclient.executeMethod(postMethod);
retStream = postMethod.getResponseBodyAsStream(); return retStream;
} /**
 * http协议的处理操作
 * 
 * @param input 输入的参数伪xml字符串
 * 
 * @param httpurl 请求的url
 * @return [参数说明]
 * 
 * @return InputStream [返回的一个流]
 * @exception throws [违例类型] [违例说明]
 * @see [类、类#方法、类#成员]
 */
public InputStream excuteHTTP(String input, String httpurl) throws Exception
{
PostMethod postMethod = new PostMethod(httpurl);
postMethod.setRequestHeader("Connection", "close");
RequestEntity requestEntity = new ByteArrayRequestEntity(input.getBytes("UTF-8"), "text/xml;charset=UTF-8");
postMethod.setRequestEntity(requestEntity); HttpClient httpclient = new HttpClient();
InputStream retStream = null; // 设置为10秒无响应即超时
HttpClientParams httparams = new HttpClientParams();
httparams.setSoTimeout(10000);
httpclient.setParams(httparams); httpclient.executeMethod(postMethod);
retStream = postMethod.getResponseBodyAsStream(); return retStream;
}
}