有一个网站上有几个下拉框,我已经制作了一个安卓应用程序来获取该网站的值。现在该网站有一个搜索框,在该网站中,我们可以从框中选择选项并按提交按钮,然后它将根据所选选项提供结果。我需要在我的应用程序中做同样的事情。
需要帮助,谢谢。
有一个网站上有几个下拉框,我已经制作了一个安卓应用程序来获取该网站的值。现在该网站有一个搜索框,在该网站中,我们可以从框中选择选项并按提交按钮,然后它将根据所选选项提供结果。我需要在我的应用程序中做同样的事情。
需要帮助,谢谢。
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("your_1", "data 1"));
nameValuePairs.add(new BasicNameValuePair("your_2", "data 2"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
发送请求后,您需要使用StringBuilder读取响应内容。
private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
// Return full string
return total;
}
现在您已经获得了响应,可以使用正则表达式来强调您的特殊文本。这有点棘手,但是这里可以帮助你。