HTTP GET 请求

来源:互联网 发布:多序列比对算法 编辑:程序博客网 时间:2024/06/16 10:14
/**
  * HTTP GET方式
  *
  * @param url
  * @return
  * @throws IOException
  * @throws ClientProtocolException
  */
 public static String sendHttpForGet(String url) throws ClientProtocolException, IOException {
  HttpClient client = null;
  try {
   client = new DefaultHttpClient();
   client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, httpClientConnectionTimeout);
   client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, httpClinetSoTimeout);
   HttpGet get = new HttpGet(url);
   HttpResponse httpResponse = client.execute(get);
   String respData = EntityUtils.toString(httpResponse.getEntity());
   return respData;
  } finally {
   client.getConnectionManager().shutdown();
  }
 }