Using JAVA to send HTTPS POST and GET requests - Printable Version +- Ewon Technical Forum (https://techforum.ewon.biz) +-- Forum: Development (https://techforum.ewon.biz/forum-50.html) +--- Forum: Java (https://techforum.ewon.biz/forum-53.html) +--- Thread: Using JAVA to send HTTPS POST and GET requests (/thread-1047.html) |
Using JAVA to send HTTPS POST and GET requests - AndreasABB - 17-10-2019 Hi, I've been working with an eWON Flexy 205 for a short amount of time now. I have an application (Java 11) which obviously needs to be refactored to Java 1.4.4. So far I've managed to adapt. However, I cannot find any usefull information about how to send HTTPS POST and HTTPS GET requests. I've been told it's possible, but so far I've had no luck. I've read all eWON Java pdf's I could find, as well as the BASIC User Guide. I need to be able to read the HTTPS response as well. Kind regards, Andreas TL;DR: How to send HTTPS GET and POST requests and how to read them using java? RE: Using JAVA to send HTTPS POST and GET requests - simon - 17-10-2019 Andreas, The only way to do is to use the REQUESTHTTPX function (in ScheduleActionManager class). This function allows you to customize the header and the body to send and you get the response into a file. Simon RE: Using JAVA to send HTTPS POST and GET requests - AndreasABB - 18-10-2019 Hi Simon, First of all, thanks for the quick reply. Second, is there an example somewhere that I could look into or an API of some sort regarding both using RequestHttpX() and retrieving data from a HTTPS Response? Thanks in advance, Kind regards, Andreas RE: Using JAVA to send HTTPS POST and GET requests - simon - 30-10-2019 Andreas, The function usage is the same as in BASIC except that the RESPONSEHTTPX is not implemented in JAVA. So, you should have a look at the BASIC manual : https://developer.ewon.biz/content/basic-1 Simon RE: Using JAVA to send HTTPS POST and GET requests - AndreasABB - 31-10-2019 Simon, I've tried that, but I cannot figure out how it works. Perhaps some code of what I'm trying to do helps: Code: try { Thanks in advance, Andreas RE: Using JAVA to send HTTPS POST and GET requests - simon - 07-11-2019 Andreas, The equivalent should be : Code: int status = com.ewon.ewonitf.ScheduledActionManager.RequestHttpX("https://web.com", Hope it helps Simon RE: Using JAVA to send HTTPS POST and GET requests - LewisH304 - 29-11-2019 Code: package com.journaldev.utils; Regards, Lewis RE: Using JAVA to send HTTPS POST and GET requests - simon - 03-12-2019 Hi Lewis, The java.net.HttpURLConnection class is unfortunately not supported by our JVM. You must use the proprietary function REQUESTHTTPX. Simon RE: Using JAVA to send HTTPS POST and GET requests - LewisH304 - 04-04-2020 Below are the steps we need to follow for sending Java HTTP requests using HttpURLConnection class. Create URL object from the GET/POST URL String. Call openConnection() method on URL object that returns instance of HttpURLConnection Set the request method in HttpURLConnection instance, default value is GET. Call setRequestProperty() method on HttpURLConnection instance to set request header values, such as “User-Agent” and “Accept-Language” etc. We can call getResponseCode() to get the response HTTP code. This way we know if the request was processed successfully or there was any HTTP error message thrown. For GET, we can simply use Reader and InputStream to read the response and process it accordingly. For POST, before we read response we need to get the OutputStream from HttpURLConnection instance and write POST parameters into it. RE: Using JAVA to send HTTPS POST and GET requests - simon - 08-04-2020 Again, this class is NOT supported by the Ewon Flexy JVM. Use the ScheduleActionsManager to get the proper functions to send or read data through HTTP(S) RE: Using JAVA to send HTTPS POST and GET requests - esp70 - 07-05-2020 (08-04-2020, 08:56 PM)simon Wrote: Again, this class is NOT supported by the Ewon Flexy JVM.Hey Simon- New user here and I am trying to organize my project goals. HTTP POST/GETs are a priority to understand if there are limitations with the Flexy. I see you say that the HttpURLConnection is not supported by the Ewon Flexy JVM, yet it is a part of the java.net package that is included in the javaetk.jar (java 1.4). I do not have access to an eWON Flexy at all times of development, and if you are correct, then how do I know what the JVM will run without testing each and every Java class individually within Flexy? I would think that the Flexy JVM could run every class that is within the javaetk.jar?? I am hoping that I misunderstood your answer but it sure does seem like we should be able to use all classes within the javaetk.jar that compiles to it in eclipse. Best Regards, Eric RE: Using JAVA to send HTTPS POST and GET requests - simon - 07-05-2020 Hi Eric, I have finally tested the class by myself and it partially works. Actually I have used an example based on https://www.journaldev.com/7148/java-httpurlconnection-example-java-http-request-get-post I have tried to connect to an url with a name (http://mysite.com) and it returned a DNS error. By using an IP it worked. So it seems there is a problem with the DNS resolution when using this class. If I use an HTTPS link, it clearly states that the HTTPS is NOT implemented. So, in short, if you want to use HTTPS and/or a name into the url, you must use the RequestHttpX() function. 2020-05-07_19-01-41.png (Size: 35,61 KB / Downloads: 20) See also https://hmsnetworks.blob.core.windows.net/www/docs/librariesprovider10/downloads-monitored/manuals/knowledge-base/kb-0256-00-en-get-put-https-request-using-basic-script-or-java.pdf?sfvrsn=166256d7_6 So, yes, everything that is in the javaetk.jar should be supported, but that is not always true unfortunately. If you tell me more about the project, I may be able to tell you if it is possible and what functions to use. Simon RE: Using JAVA to send HTTPS POST and GET requests - esp70 - 08-05-2020 (07-05-2020, 11:59 PM)simon Wrote: Hi Eric, Simon, Thank you for the quick reply! For the HTTP portion of my project, I have to make sure that we can push zipped files (hopefully the zip libraries work!!) to a HTTP server. In fact, I would like to stream the files with Multipart form data or as an Octet stream if possible. Again, I do not have a Flexy currently to test this, I would just setup my eclipse to perform the testing on my server. On a side note...is there any source code for javaetk that are posted? It seems like that would go a long way at understanding the system? Regards, Eric RE: Using JAVA to send HTTPS POST and GET requests - simon - 11-05-2020 Hi Eric, Yes, zipping a file should work. I have already tested that and it worked (but it may take some time according to the size of the file to zip): Code: public static void main(String[] args) throws Exception { Regarding the Data post, the multipart form data is what the PUTHTTP or REQUESTHTTPX functions do when you define some files to upload (4th arg of PUTHTTP function and 5th arg of the RequesHttpX function). You can refer to the BASIC manual for that (functions definition are very similar) https://developer.ewon.biz/system/files_force/rg-0006-01-en-basic-programming.pdf?download=1. Simon |