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.
By this way we can send data with http post method and get result
to @primpop answer I would add how to convert the response in a String:
Here is an example of convertStramToString.
For me works next :
for Android 6 & 5
The org.apache.http classes and the AndroidHttpClient class have been deprecated in Android 5.1. These classes are no longer being maintained and you should migrate any app code using these APIs to the URLConnection classes as soon as possible.
https://developer.android.com/about/versions/android-5.1.html#http
Thought of sharing my code using HttpUrlConnection
...
also you can Post method :
Update 21/02/2016
for post request with json , see this example :
UPDATE 24/08/2016
Use some best library , such as :
because :
On lower API levels (mostly on Gingerbread and Froyo), HttpUrlConnection and HttpClient are far from being perfect
Since the introduction of Honeycomb (API 11), it's been mandatory to perform network operations on a separate thread, different from the main thread
* Updated Answer which works on Android 6.0+. Thanks to @Rohit Suthar, @Tamis Bolvari and @sudhiskr for the comments. *
References:
Older Answer
Note: This solution is outdated. It only works on Android devices up to 5.1. Android 6.0 and above do not include the Apache http client used in this answer.
Http Client from Apache Commons is the way to go. It is already included in android. Here's a simple example of how to do HTTP Post using it.
I found this helpful example with this video tutorial.