Android web 以编程方式设置输入和读取数据

Android web set input and read data programmatically

我希望我的应用程序在网页上设置输入(select框),以便可以读取结果 html 代码。 Htmlcode 如下所示:

<select name="element" class="selectbox" style="width:114" size="12" onchange="doDisplayTimetable(NavBar, topDir);">  
<option value="1">5a</option>  
<option value="2">5b</option>  
<option value="3">5c</option>  
<option value="4">5d</option>  
<option value="5">5e</option>  
<option value="6">6a</option>  
<option value="7">6b</option>   
<option value="8">6c</option>  
<option value="9">6d</option>  
<option value="10">7a</option>  
<option value="11">7b</option>  
<option value="12">7c</option>  
<option value="13">7d</option>  
<option value="14">7e</option>  
<option value="15">8a</option>  
<option value="16">8b</option>  
<option value="17">8c</option>  
<option value="18">8d</option>  
<option value="19">8e</option>  
<option value="20">9a</option>  
<option value="21">9b</option>  
<option value="22">9c</option>  
<option value="23">9d</option>

App 现在应该 select 23 然后将 Htmlcode 存储在一个字符串中。请帮助:)

String downloadURL = "your url";
try {
            URL url = new URL(downloadURL);
            String urlParameters = "";
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded");

            connection.setRequestProperty("Content-Length",
                    "" + Integer.toString(urlParameters.getBytes().length));
            connection.setRequestProperty("Content-Language", "en-US");

            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);

            DataOutputStream wr = new DataOutputStream(
                    connection.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();

            InputStream inputStream = connection.getInputStream();
            //This inputstream contains html
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            workingInternet = false;

        }

urlParameters 字符串的格式为

String urlParameters = "inputBoxname1"
                    + URLEncoder.encode(inputValue1, "UTF-8")
                    + "&inputBoxname2="
                    + URLEncoder.encode(inputValue2, "UTF-8");