/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.httpclient.Header
 *  org.apache.commons.httpclient.HttpClient
 *  org.apache.commons.httpclient.HttpMethod
 *  org.apache.commons.httpclient.methods.GetMethod
 *  org.apache.commons.httpclient.methods.PostMethod
 */
package com.hst.taxService.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class HttpUtils {
    public static String doPost(String url, Map<String, String> params, String charset, boolean pretty) {
        StringBuffer response;
        block10: {
            System.out.println(url);
            response = new StringBuffer();
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod(url);
            post.setRequestHeader(new Header("Content-type", "application/x-www-form-urlencoded;charset=gbk"));
            post.setRequestHeader(new Header("User-Agent", "Mozilla/5.0 /Windows; U; Windows NT 4.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.0"));
            if (params != null) {
                for (Map.Entry<String, String> entry : params.entrySet()) {
                    post.setParameter(entry.getKey(), entry.getValue());
                }
            }
            try {
                try {
                    client.executeMethod((HttpMethod)post);
                    if (post.getStatusCode() == 200) {
                        String line;
                        BufferedReader reader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream(), charset));
                        while ((line = reader.readLine()) != null) {
                            if (pretty) {
                                response.append(line).append(System.getProperty("line.separator"));
                                continue;
                            }
                            response.append(line);
                        }
                        reader.close();
                    }
                }
                catch (IOException e) {
                    e.printStackTrace();
                    post.releaseConnection();
                    break block10;
                }
            }
            catch (Throwable throwable) {
                post.releaseConnection();
                throw throwable;
            }
            post.releaseConnection();
        }
        return response.toString();
    }

    public static String doGet(String url, Map<String, String> params, String charset, boolean pretty) {
        StringBuffer response;
        block11: {
            System.out.println(url);
            response = new StringBuffer();
            HttpClient client = new HttpClient();
            StringBuilder sb = new StringBuilder();
            if (params != null) {
                for (Map.Entry<String, String> entry : params.entrySet()) {
                    sb.append(entry.getKey());
                    sb.append("=");
                    sb.append(entry.getValue());
                    sb.append("&");
                }
            }
            if (sb.length() > 0) {
                url = String.valueOf(url) + "?" + sb.toString().substring(0, sb.toString().length() - 1);
            }
            System.out.println(url);
            GetMethod get = new GetMethod(url);
            get.setRequestHeader(new Header("Content-type", "application/x-www-form-urlencoded;charset=gbk"));
            get.setRequestHeader(new Header("User-Agent", "Mozilla/5.0 /Windows; U; Windows NT 4.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.0"));
            try {
                try {
                    client.executeMethod((HttpMethod)get);
                    if (get.getStatusCode() == 200) {
                        String line;
                        BufferedReader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), charset));
                        while ((line = reader.readLine()) != null) {
                            if (pretty) {
                                response.append(line).append(System.getProperty("line.separator"));
                                continue;
                            }
                            response.append(line);
                        }
                        reader.close();
                    }
                }
                catch (IOException e) {
                    e.printStackTrace();
                    get.releaseConnection();
                    break block11;
                }
            }
            catch (Throwable throwable) {
                get.releaseConnection();
                throw throwable;
            }
            get.releaseConnection();
        }
        return response.toString();
    }
}
