I'm experienced with PHP, JavaScript and a lot of other scripting languages, but I don't have a lot of experience with Java or Android.
I'm looking for a way to send POST data to a PHP script and display the result.
I'm experienced with PHP, JavaScript and a lot of other scripting languages, but I don't have a lot of experience with Java or Android.
I'm looking for a way to send POST data to a PHP script and display the result.
You can POST an HttpRequest using WebServer class and track the response in its listener interface.
Now create a DataRack to bind your data
Now simply send the POST request with that rack
You need to include my library for this. Documentations here
You can use
URLConnection
withsetDoOutput
(true)
,getOutputStream()
(for sending data), andgetInputStream()
(for receiving). Sun has an example for exactly this.Better use Apache Commons HttpClient, that is also included in android already. Have a look at Android Developer: Apache HTTP Client Package Summary for general api info.
If you just want to append data to the Url You can do so by using HttpUrlConnection since HttpClient is now deprecated. A better way would be to use a library like-
Volley Retrofit
We can post data to the php script and fetch result and display it by using this code performed Through AsyncTask class.
But using libraries such as volley or retrofit is much better option because Asynctask class and HttpurlConnection is slower compared to libraries. Also the library will fetch everything and is faster as well.
Method to post data as HTTP request,
In newer versions of Android you have to put all web I/O requests into a new thread. AsyncTask works best for small requests.