// gets VM home and data page based on boolean parameter
  public static String fetchURL(String username, String password, Boolean getData) {
    String line = "";

    String url = "https://www2.virginmobileusa.com/login/login.do";
    String dataUrl = "https://www2.virginmobileusa.com/myaccount/dataPlanHistory.do";
    try {
      TrustManager[] trustAllCerts =
          new TrustManager[] {
            new X509TrustManager() {
              public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
              }

              public void checkClientTrusted(
                  java.security.cert.X509Certificate[] certs, String authType) {}

              public void checkServerTrusted(
                  java.security.cert.X509Certificate[] certs, String authType) {}
            }
          };
      try {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      } catch (Exception e) {
        e.getMessage();
      }

      HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
      ((HttpsURLConnection) connection).setHostnameVerifier(new AllowAllHostnameVerifier());

      connection.setDoOutput(true);

      String content = "loginRoutingInfo=&min=" + username + "&vkey=" + password + "&submit=submit";

      connection.setFixedLengthStreamingMode(content.length());
      connection.setRequestProperty("Host", "www2.virginmobileusa.com");
      connection.setRequestProperty("Accept-Language", "en-US,en;q=0.9");

      OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
      out.write(content);
      out.close();

      InputStreamReader in = new InputStreamReader((InputStream) connection.getContent());

      BufferedReader buff = new BufferedReader(in);

      StringBuilder sb = new StringBuilder();

      while ((line = buff.readLine()) != null) {
        sb.append(line);
      }

      // telephone
      int tel_infoStartIndex = sb.indexOf("id=\"headerimage\"");
      int tel_infoEndIndex = sb.indexOf("<ul class=\"tabnav\">");
      // balance info
      int balance_infoStartIndex = sb.indexOf("id=\"balance_info2b\">");
      int balance_infoEndIndex = sb.indexOf("id=\"payment_strip\"");
      // account activity
      int account_activityStartIndex = sb.indexOf("id=\"account_activity\"");
      int account_activityEndIndex = sb.indexOf("id=\"for_your_phone\"");

      // int mainContentIndex = sb.indexOf("id=\"mainContent\"");
      if (tel_infoStartIndex == -1) {
        line = "";
      } else {
        line = sb.substring(tel_infoStartIndex, tel_infoEndIndex);
      }
      if (balance_infoStartIndex != -1) {

        line += sb.substring(balance_infoStartIndex, balance_infoEndIndex);
      }
      if (account_activityStartIndex != -1) {
        line += sb.substring(account_activityStartIndex, account_activityEndIndex);
      }
      // Now, try to grab data usage
      String cookies = "";
      // 1. Grab and store cookies
      String headerName = null;
      for (int i = 1; (headerName = connection.getHeaderFieldKey(i)) != null; i++) {
        if (headerName.equalsIgnoreCase("Set-Cookie")) {
          String cookie = connection.getHeaderField(i);
          cookie = cookie.substring(0, cookie.indexOf(";"));
          String cookieName = cookie.substring(0, cookie.indexOf("="));
          String cookieValue = cookie.substring(cookie.indexOf("=") + 1, cookie.length());
          cookies = cookies + cookieName + "=" + cookieValue + "; ";
        }
      }
      if (getData == true) {
        // get data page
        HttpsURLConnection connection2 = (HttpsURLConnection) new URL(dataUrl).openConnection();
        ((HttpsURLConnection) connection2).setHostnameVerifier(new AllowAllHostnameVerifier());

        connection2.setDoOutput(true);
        connection2.setRequestProperty("Cookie", cookies);
        connection2.connect();
        InputStreamReader in2 = new InputStreamReader((InputStream) connection2.getContent());

        BufferedReader buff2 = new BufferedReader(in2);

        StringBuilder sb2 = new StringBuilder();

        String dataPage;
        while ((dataPage = buff2.readLine()) != null) {
          sb2.append(dataPage);
        }

        int dataContentIndex = sb2.indexOf("<h2>Mobile Web History</h2>");
        if (dataContentIndex == -1) {
          dataPage = "";
        } else {
          dataPage = sb2.substring(dataContentIndex);
          line += ("****************" + dataPage);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      // System.err.println("exception 83");
      // System.err.println(e.getMessage());
      // System.err.println(line);
      return line;
      // rc.put("isValid", "FALSE");
    }
    return line;
  }
  public static String fetchScreen(String username, String password) {
    String line = "";

    try {
      TrustManager[] trustAllCerts =
          new TrustManager[] {
            new X509TrustManager() {
              public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
              }

              public void checkClientTrusted(
                  java.security.cert.X509Certificate[] certs, String authType) {}

              public void checkServerTrusted(
                  java.security.cert.X509Certificate[] certs, String authType) {}
            }
          };

      String url = "https://www2.virginmobileusa.com/login/login.do";
      String dataUrl = "https://www2.virginmobileusa.com/myaccount/dataPlanHistory.do";
      // String url = "https://www1.virginmobileusa.com/login/login.do";
      //   String url = "https://www1.virginmobileusa.com/myaccount/home.do";

      try {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      } catch (Exception e) {
        e.getMessage();
      }

      // HttpsURLConnection.setFollowRedirects(true);

      HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
      ((HttpsURLConnection) connection).setHostnameVerifier(new AllowAllHostnameVerifier());

      // connection.setFollowRedirects(true);

      connection.setDoOutput(true);

      String content = "loginRoutingInfo=&min=" + username + "&vkey=" + password + "&submit=submit";

      connection.setFixedLengthStreamingMode(content.length());
      connection.setRequestProperty("Host", "www2.virginmobileusa.com");
      connection.setRequestProperty("Accept-Language", "en-US,en;q=0.9");

      // try {
      // Thread.sleep(5000);
      OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
      out.write(content);
      out.close();
      // } catch (IOException e) {
      //   e.printStackTrace();
      // }

      // connection.connect();

      InputStreamReader in = new InputStreamReader((InputStream) connection.getContent());

      BufferedReader buff = new BufferedReader(in);

      StringBuilder sb = new StringBuilder();

      while ((line = buff.readLine()) != null) {
        sb.append(line);
      }

      int mainContentIndex = sb.indexOf("id=\"mainContent\"");
      if (mainContentIndex == -1) {
        line = "";
      } else {
        line = sb.substring(mainContentIndex);
      }

      // Now, try to grab data usage
      String cookies = "";
      // 1. Grab and store cookies
      String headerName = null;
      for (int i = 1; (headerName = connection.getHeaderFieldKey(i)) != null; i++) {
        if (headerName.equalsIgnoreCase("Set-Cookie")) {
          String cookie = connection.getHeaderField(i);
          cookie = cookie.substring(0, cookie.indexOf(";"));
          String cookieName = cookie.substring(0, cookie.indexOf("="));
          String cookieValue = cookie.substring(cookie.indexOf("=") + 1, cookie.length());
          cookies = cookies + cookieName + "=" + cookieValue + "; ";
        }
      }
      // connection.disconnect();

      // 2. Grab the next page
      BufferedReader buff2 = new BufferedReader(in);

      StringBuilder sb2 = new StringBuilder();

      connection = (HttpsURLConnection) new URL(dataUrl).openConnection();
      ((HttpsURLConnection) connection).setHostnameVerifier(new AllowAllHostnameVerifier());

      // connection.setFollowRedirects(true);
      connection.setDoOutput(true);
      connection.setRequestProperty("Cookie", cookies);

      // connection.connect();

      in = new InputStreamReader((InputStream) connection.getContent());

      buff2 = new BufferedReader(in);

      sb2 = new StringBuilder();

      String dataPage;
      while ((dataPage = buff2.readLine()) != null) {
        sb2.append(dataPage);
      }

      int dataContentIndex = sb2.indexOf("<h2>Mobile Web History</h2>");
      if (dataContentIndex == -1) {
        dataPage = "";
      } else {
        dataPage = sb2.substring(dataContentIndex);
      }

      // Simply concat the output with our data page output
      if (line != null) {

        // line.concat("---------------TEST----------------------"+ dataPage);
        // line = dataPage;
      }
    } catch (Exception e) {
      e.printStackTrace();
      // System.err.println("exception 83");
      // System.err.println(e.getMessage());
      // System.err.println(line);
      return line;
      // rc.put("isValid", "FALSE");
    }
    // line = null;
    if (line == null) {
      // line = "";
    }
    // System.err.println(line);
    return line;
  }