I am making an application which takes a URL with. *.asp extension and we pass it the required parameters and get some string result using POST method.
Any suggestions on how to achieve this?
UPDATED:
Actually I have a .net link which takes some POST Parameters and gives me a Result. How can I do that in Android?
HTTPResponse should do the trick:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoururl.com");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); <!-- number should be the amount of parameters
nameValuePairs.add(new BasicNameValuePair("nameOfParameter", "parameter"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
InputStream is = buf.getContent();
Now you got a stream to work with, to write the data to a string:
BufferedReader r = new BufferedReader(new InputStreamReader(is));
total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
Good luck!
try using an AsynTask ( http://developer.android.com/reference/android/os/AsyncTask.html ) and never try to make any time consuming tasks in the onCreate call or any other GUI thread method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With