An HtmlUnit alternative for android?

Guys I kind of found another method. Since I know the servers address I tried to post the data directly to it using a DataOutputStream. Look at the code below:

public String searchDirectory() throws IOException {
    URL url = new URL("https://www.xxxxx.com/xxxxx/xxxxx.cgi");
    URLConnection con = url.openConnection();
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    DataOutputStream printout = new DataOutputStream (con.getOutputStream ());

    String parameters =("name=" + URLEncoder.encode("DATA HERE", "UTF-8"));
    printout.writeBytes (parameters);
    printout.flush ();
    printout.close ();
        /*InputStream inputStream = getApplicationContext().getResources().getAssets().open("White Pages Query Results.html");
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        */
    DataInputStream input = new DataInputStream (con.getInputStream ());
    String line;
    String htmlCode = "";
    while((line = input.readLine()) != null) {
        htmlCode += line;
    }
    return htmlCode;
}

As you can see I’m using the names of the Html Elements to access them through java. However as you can see from the html form code in original post the radio buttons have the same name, how can I access/fill them separately without using their names??

Leave a Comment