An HtmlUnit alternative for android?

后端 未结 1 1167
花落未央
花落未央 2020-12-02 01:07

An alternative that allows me to fill an HTML form that has checkboxes and radiobuttons.

I was creating this android app that asks user input and sends that data to

相关标签:
1条回答
  • 2020-12-02 01:44

    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??

    0 讨论(0)
提交回复
热议问题