From 3f76813e80102edfe247425cc385de4e75bd8d17 Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 12 Dec 2023 23:40:12 +0100 Subject: [PATCH] Http method selectable --- .../java/com/jens/automation2/Action.java | 2 +- .../java/com/jens/automation2/AsyncTasks.java | 2 +- .../com/jens/automation2/Miscellaneous.java | 40 +++++++++---------- .../main/java/com/jens/automation2/News.java | 2 +- .../metadata/android/en-US/changelogs/138.txt | 3 +- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index b6cf8d85..d2694aef 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -674,7 +674,7 @@ public class Action Miscellaneous.logEvent("i", "HTTP", "Attempting download of " + url, 4); //getResources().getString("attemptingDownloadOf"); if(this.getParameter1()) // use authentication - new DownloadTask().execute(url, username, password, methodnochindiesignaturaufnehmen); + new DownloadTask().execute(url, username, password, method); else new DownloadTask().execute(url, null, null); } diff --git a/app/src/main/java/com/jens/automation2/AsyncTasks.java b/app/src/main/java/com/jens/automation2/AsyncTasks.java index 793e2f40..4b7401fd 100644 --- a/app/src/main/java/com/jens/automation2/AsyncTasks.java +++ b/app/src/main/java/com/jens/automation2/AsyncTasks.java @@ -22,7 +22,7 @@ public class AsyncTasks try { - String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null).trim(); + String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null, ActivityManageActionTriggerUrl.methodGet).trim(); int latestVersion = Integer.parseInt(result); // At this point the update check itself has already been successful. diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index 97bf03a3..4da9c912 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -48,6 +48,7 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; @@ -181,9 +182,7 @@ public class Miscellaneous extends Service public static String downloadURLwithoutCertificateChecking(String url, String username, String password, String method) { - boolean errorFound = false; - - try + try { HttpParams params = new BasicHttpParams(); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); @@ -191,23 +190,23 @@ public class Miscellaneous extends Service HttpClient httpclient = new DefaultHttpClient(params); httpclient = Actions.getInsecureSslClient(httpclient); - HttpEntityEnclosingRequestBase httpRequest; - switch (method) - { - case ActivityManageActionTriggerUrl.methodPost: - httpRequest = new HttpPost(url); - break; - case ActivityManageActionTriggerUrl.methodGet: - default: - httpRequest = new HttpEntityEnclosingRequestBase() + HttpRequestBase httpRequest; + if( + method.equals(ActivityManageActionTriggerUrl.methodPost) + || + (username != null && password != null) + ) + httpRequest = new HttpPost(url); + else + httpRequest = new HttpGet(url); + /*httpRequest = new HttpEntityEnclosingRequestBase() + { + @Override + public String getMethod() { - @Override - public String getMethod() - {somethingMissing - return null; - } - }; - } + return "GET"; + } + };*/ // Add http simple authentication if specified if(username != null && password != null) @@ -227,8 +226,7 @@ public class Miscellaneous extends Service catch(Exception e) { Miscellaneous.logEvent("e", "HTTP error", Log.getStackTraceString(e), 3); - errorFound = true; - return "httpError"; + return "httpError"; } // finally // { diff --git a/app/src/main/java/com/jens/automation2/News.java b/app/src/main/java/com/jens/automation2/News.java index 040b8de4..f4a9ca64 100644 --- a/app/src/main/java/com/jens/automation2/News.java +++ b/app/src/main/java/com/jens/automation2/News.java @@ -79,7 +79,7 @@ public class News if (!(new File(filePath)).exists() || Settings.lastNewsPolltime == Settings.default_lastNewsPolltime || now.getTimeInMillis() >= Settings.lastNewsPolltime + (long)(Settings.newsDisplayForXDays * 24 * 60 * 60 * 1000)) { String newsUrl = "https://server47.de/automation/appNews.php"; - newsContent = Miscellaneous.downloadURL(newsUrl, null, null); + newsContent = Miscellaneous.downloadURL(newsUrl, null, null, ActivityManageActionTriggerUrl.methodGet); // Cache content to local storage if(Miscellaneous.writeStringToFile(filePath, newsContent)) diff --git a/fastlane/metadata/android/en-US/changelogs/138.txt b/fastlane/metadata/android/en-US/changelogs/138.txt index ae7eecd7..7c8e11a0 100644 --- a/fastlane/metadata/android/en-US/changelogs/138.txt +++ b/fastlane/metadata/android/en-US/changelogs/138.txt @@ -1,2 +1,3 @@ * Fixed: Overlay permission for start other program action only required if startByActivity() is selected -* Fixed: Broadcast receiver trigger would not trigger anything, but crash \ No newline at end of file +* Fixed: Broadcast receiver trigger would not trigger anything, but crash +* Added: One can now choose between GET and POST when using triggerURL action \ No newline at end of file