Im a newbie at android coding and I looked around a little to try to find a solution to my problem. The web-site I want to send the data has a form. I want to collect data from my activity in edittext fields and send it to the Web form and submit the web-form.
After some reading online I am across the below method. Can someone tell me if this is correct? If the webform has a field called “name” (I can access the site source). And the user enters “John Doe”, So the NameValue pair will be “name”,”John Doe” right?
HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),10000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(),10000);
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name1", "value1"));
nameValuePairs.add(new BasicNameValuePair("name2", "value2"));
nameValuePairs.add(new BasicNameValuePair("name3", "value3"));
// etc...
try{
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
}
catch(Exception e)
{
}
Yes, you are submitting the data via post.
Just in case you don’t know this: You should post the data to the “form action” page.