package com.sino.weixin.oauth.util;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;



public class HttpUtil {
	private static Log log = LogFactory.getLog(HttpUtil.class);
	
	
	public static String getUrl(String url){
        String result = null;
        try {
            // 根据地址获取请求
            HttpGet request = new HttpGet(url);
            // 获取当前客户端对象
            DefaultHttpClient httpClient = new DefaultHttpClient();
            // 通过请求对象获取响应对象
            HttpResponse response = httpClient.execute(request);
            // 判断网络连接状态码是否正常(0--200都数正常)
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                //result= EntityUtils.toString(response.getEntity());
                result= new String(EntityUtils.toByteArray(response.getEntity()),"UTF-8");
            } 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }
	
/**public static void main(String[] args) {
	String req = HttpUtil.getUrl("https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=XSwWeBy9OKVZX_Rw3a32CQBxhJrs8rGtpKPuzhsvpUt2sctpwa9lBLe14MioxDXTQilH_7Bu6KH9vJlyrG7a1iYhGpLAVv2RRyGn5rCvu7vMorlHGUUVnZ95oljsZPsrXTEaACAHDO");
	System.out.println(req);
}
**/



}
