From c5ef01305ee359d0423f4ed0f8a56a8bf99dad4b Mon Sep 17 00:00:00 2001 From: Vishnu Sivadas Date: Wed, 24 Jun 2020 23:51:03 +0530 Subject: [PATCH] Initial commit --- .../advanced_httpurlconnection/PutData.java | 12 ++++++------ .../advancedhttpurlconnection/MainActivity.java | 8 ++++---- app/src/main/res/layout/activity_main.xml | 8 ++++++++ app/src/main/res/values/strings.xml | 3 ++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Advanced_HttpURLConnection/src/main/java/com/vishnusivadas/advanced_httpurlconnection/PutData.java b/Advanced_HttpURLConnection/src/main/java/com/vishnusivadas/advanced_httpurlconnection/PutData.java index dd61283..8e469f9 100644 --- a/Advanced_HttpURLConnection/src/main/java/com/vishnusivadas/advanced_httpurlconnection/PutData.java +++ b/Advanced_HttpURLConnection/src/main/java/com/vishnusivadas/advanced_httpurlconnection/PutData.java @@ -14,14 +14,14 @@ public class PutData extends Thread { private String url, method; String result_data = "Empty"; - String[] data, param; + String[] data, field; - public PutData(String url, String method, String[] param, String[] data) { + public PutData(String url, String method, String[] field, String[] data) { this.url = url; this.method = method; this.data = new String[data.length]; - this.param = new String[param.length]; - System.arraycopy(param, 0, this.param, 0, param.length); + this.field = new String[field.length]; + System.arraycopy(field, 0, this.field, 0, field.length); System.arraycopy(data, 0, this.data, 0, data.length); } @@ -37,8 +37,8 @@ public void run() { OutputStream outputStream = httpURLConnection.getOutputStream(); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, UTF8)); StringBuilder post_data = new StringBuilder(); - for (int i = 0; i < this.param.length; i++) { - post_data.append(URLEncoder.encode(this.param[i], "UTF-8")).append("=").append(URLEncoder.encode(this.data[i], UTF8)).append("&"); + for (int i = 0; i < this.field.length; i++) { + post_data.append(URLEncoder.encode(this.field[i], "UTF-8")).append("=").append(URLEncoder.encode(this.data[i], UTF8)).append("&"); } bufferedWriter.write(post_data.toString()); bufferedWriter.flush(); diff --git a/app/src/main/java/com/vishnusivadas/advancedhttpurlconnection/MainActivity.java b/app/src/main/java/com/vishnusivadas/advancedhttpurlconnection/MainActivity.java index f7ef9d6..d0a1f6f 100644 --- a/app/src/main/java/com/vishnusivadas/advancedhttpurlconnection/MainActivity.java +++ b/app/src/main/java/com/vishnusivadas/advancedhttpurlconnection/MainActivity.java @@ -60,14 +60,14 @@ public void onClick(View v) { public void run() { //Starting Write and Read data with URL //Creating array for parameters - String[] param = new String[2]; - param[0] = "param-1"; - param[1] = "param-2"; + String[] field = new String[2]; + field[0] = "param-1"; + field[1] = "param-2"; //Creating array for data String[] data = new String[2]; data[0] = "data-1"; data[1] = "data-2"; - PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data); + PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", field, data); if (putData.startPut()) { if (putData.onComplete()) { String result = putData.getResult(); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0ef9fa6..cdd4511 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -39,4 +39,12 @@ style="@style/Widget.AppCompat.Button.Colored" android:theme="@style/Widget.AppCompat.Button.Colored"/> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afc1b95..e341203 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ AdvancedHttpURLConnection - Fetching Data + Result Text Fetch Data Put Data + GitHub.com/VishnuSivadasVS \ No newline at end of file