import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
/**
* http invoker for doPost request or doGet request, return memory stream
* <code>OutputStream</code>,ie. <code>ByteArrayOutputStream</code>
*
*
* @author
* @see org.apache.http.client.HttpClient
*/
public class HttpInvoker
{
/**
* doGet方式访问URL
*
* @param url
* @return OutputStream
*/
public static OutputStream doGet(String url)
{
HttpClient httpclient = new DefaultHttpClient();
OutputStream os = null;
try
{
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null)
{
InputStream instream = entity.getContent();
os = new ByteArrayOutputStream();
int temp = 0;
while ((temp = instream.read()) != -1)
{
os.write(temp);
}
os.flush();
os.close();
return os;
}
}
catch (Exception e)
{
}
finally
{
httpclient.getConnectionManager().shutdown();
}
return null;
}<\]JN[[[OH\N[]\[[[OH\N[O[[[OH\N[O[[[OH\N[
^[JO[[[OH\N[KKHKO[[[OH\N[O[[[OH\N[[[O[[[OH\N[KKHKO[[[OH\N[Y[X[X[Y
K]
N[[[OH\N[O[[[OH\N[]\[[[[OH\N[O[[[OH\N[O[]] |