From 7ddd7bd31dffa661a4aeba1d5a62a83200d7602f Mon Sep 17 00:00:00 2001 From: Vishnu Sivadas Date: Wed, 24 Jun 2020 22:57:56 +0530 Subject: [PATCH] Update README.md --- README.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d4a09b..5f44656 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ We have Two classes FetchData and PutData. Import the Library to your file first ### Read Data From a URL - FetchData.class You need to use Handler and post a Runnable. Inside the run method add the code for FetchData. -* Creating the object for FetchData. +* Creating the object for FetchData, pass the URL as argument. ``` FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php"); ``` @@ -63,6 +63,40 @@ handler.post(new Runnable() { ``` ### Write data with POST and GET methods - PutData.class +You need to use Handler and post a Runnable. Inside the run method add the code for PutData. + +* First we need to create to arrays, one for field name of the parameter and another for the data. Make sure the order is correct. +``` +String[] param = new String[2]; +param[0] = "param-1"; +param[1] = "param-2"; +String[] data = new String[2]; +data[0] = "data-1"; +data[1] = "data-2"; +``` +* PHP representation, The post array will look like, +``` +$_POST['param-1'] = "data-1"; +$_POST['param-2'] = "data-2"; +``` + +* Creating the object for PutData, pass the URL, method, field, data as arguments. The method can be POST and also GET. +``` +PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data); +``` +* Calling startFetch() for starting the process, it returns a boolean value. +``` +putData.startFetch(); +``` +* To know when the process is completes use onComplete() which returns a boolean value. +``` +putData.onComplete(); +``` +* If the process is complete, use the getResult() to get the result value. +``` +putData.getResult(); +``` +* Full implimentation with Handler. You can also add a progress bar at the commended regions. ``` //Start ProgressBar first (Set visibility VISIBLE) Handler handler = new Handler(); @@ -78,7 +112,7 @@ handler.post(new Runnable() { String[] data = new String[2]; data[0] = "data-1"; data[1] = "data-2"; - PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "GET", param, data); + PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data); if (putData.startFetch()) { if (putData.onComplete()) { String result = putData.getResult();