I have searched everywhere but I couldn't find my answer, is there a way to make an simple HTTP request? I want to request an PHP page / script on one of my website but I don't want to show the webpage.
If possible I even want to do it in the background (in an BroadcastReceiver)
I made this for a webservice to requerst on URL, using a Gson lib:
Client:
unless you have an explicit reason to choose the Apache HttpClient, you should prefer java.net.URLConnection. you can find plenty of examples of how to use it on the web.
we've also improved the Android documentation since your original post: http://developer.android.com/reference/java/net/HttpURLConnection.html
and we've talked about the trade-offs on the official blog: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
Note: The Apache HTTP Client bundled with Android is now deprecated in favor of HttpURLConnection. Please see the Android Developers Blog for more details.
Add
<uses-permission android:name="android.permission.INTERNET" />
to your manifest.You would then retrieve a web page like so:
I also suggest running it on a separate thread:
See the documentation for more information on response handling and POST requests.
With a thread:
Look at this awesome new library which is available via gradle :)
build.gradle:
compile 'com.apptakk.http_request:http-request:0.1.2'
Usage:
https://github.com/erf/http-request