public static String getSessionId(URLConnection con) {
        for (String data : con.getHeaderFields().get("Set-Cookie")) {
            if (data.indexOf("JSESSIONID") != -1) {
                return data.substring(0, data.indexOf(";"));
            }
        }
        return null;
    }