Reputation: 2569
There is a website in which there are several drop down boxes.I made an android app that pulls the values from the site. Now there is a search box in the website , in the website we can choose options from the box and press submit , then it gives the result based on the options selected. I need to do the same in my app. Need help.Thanks
Upvotes: 3
Views: 1104
Reputation: 7117
To post data to a website you have send a HTTP POST request to it. You can put the data which you want to send in an array and send it to the php script.
You have to figure out with which ID your String is send to the server. In my example it is your_1 and your_2. This is different to each website. All new browsers can read this out in a developer console or something.
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
}
After you have send this you have to get the response which you can read out with a 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;
}
Now you have the response and you can emphasize your special text with RegEx. This is a little bit tricky but this will help you.
Upvotes: 4