Tutorial by Examples

In order to create a new Android HTTP Client HttpURLConnection, call openConnection() on a URL instance. Since openConnection() returns a URLConnection, you need to explicitly cast the returned value. URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnect...
URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); try { BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); // read the input stream // in this case, I simply read t...
URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); try { BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); // use a string builder to bufferize the response body //...
Create custom class for calling multipart/form-data HttpURLConnection request MultipartUtility.java public class MultipartUtility { private final String boundary; private static final String LINE_FEED = "\r\n"; private HttpURLConnection httpConn; priva...
Use a HashMap to store the parameters that should be sent to the server through POST parameters: HashMap<String, String> params; Once the params HashMap is populated, create the StringBuilder that will be used to send them to the server: StringBuilder sbParams = new StringBuilder(); ...
Quite often it's necessary to send/upload a file to a remote server, for example, an image, video, audio or a backup of the application database to a remote private server. Assuming the server is expecting a POST request with the content, here's a simple example of how to complete this task in Andro...
The following class can be used as a single class that can handle GET, POST, PUT, PATCH, and other requests: class APIResponseObject{ int responseCode; String response; APIResponseObject(int responseCode,String response) { this.responseCode = responseCode; ...

Page 1 of 1