package hls.plugin.weixin.common;

import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class HttpUtil
{
  public static String httpRequestUrl(String requestUrl, String method)
  {
    HttpClient client = new HttpClient();
    HttpMethod httpMethod = null;
    String responseMessage = "";
    if ("GET".equals(method))
      httpMethod = new GetMethod(requestUrl);
    else {
      httpMethod = new PostMethod(requestUrl);
    }

    try
    {
      client.executeMethod(httpMethod);
    } catch (HttpException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    }
    try
    {
      responseMessage = httpMethod.getResponseBodyAsString();
      httpMethod.releaseConnection();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return responseMessage;
  }
}