protected HttpURLConnection openConnection(String url, HttpMethod method, String contentType) throws IOException {
        HttpURLConnection conn;
        try {
            conn = (HttpURLConnection) new URL(url).openConnection();
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException(url + " is not a valid URL", e);
        }
        conn.setConnectTimeout(config.getConnectionTimeout());
        conn.setReadTimeout(config.getReadTimeout());
        conn.setRequestMethod(method.getMethodName());
        conn.setDoOutput(method.isDoOutput());
        conn.setDoInput(method.isDoInput());
        if (config.getDefaultHeaders() != null) {
            for (String name : config.getDefaultHeaders().keySet()) {
                String value = config.getDefaultHeaders().get(name);
                conn.setRequestProperty(name, value);
            }
        }
        if (contentType != null) {
            conn.setRequestProperty("Content-Type", contentType);
        }
        conn.setRequestProperty("Accept-Charset", "utf8");
        return conn;
    }