MOGSY Posted February 3, 2020 Share Posted February 3, 2020 Hi How to send a http request from UniGui? Appreciate an example. Thanks. Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted February 4, 2020 Share Posted February 4, 2020 Do you want to send from client-side or Server-side? Quote Link to comment Share on other sites More sharing options...
MOGSY Posted February 4, 2020 Author Share Posted February 4, 2020 It is very usefull to be able to send to different apps and recieve from different apps. There are many situations that it is required to commuinicate with different servers i.e phone servers. I think it is better if possible to send and receive from the server side. Regards Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted February 4, 2020 Share Posted February 4, 2020 If it is server side you can use idhttp. It is same with normal vcl application Quote Link to comment Share on other sites More sharing options...
MOGSY Posted February 4, 2020 Author Share Posted February 4, 2020 it does not work, after connection it gets disconnected before sending any data. I have tried SGCWebSocket, it is the same, it will connect OK but immediatly gets disconnected. It appears that UniGui is preventing the commuincation. Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted February 4, 2020 Share Posted February 4, 2020 Hi, Can you please share your code? Unigui never prevents connections. Quote Link to comment Share on other sites More sharing options...
55143681 Posted February 6, 2020 Share Posted February 6, 2020 On 2/5/2020 at 3:01 AM, Hayri ASLAN said: Hi, Can you please share your code? Unigui never prevents connections. I think Client Mode and Server Mode are both what I needed, Can you make some test case for us, Thanks a lot. Quote Link to comment Share on other sites More sharing options...
MOGSY Posted February 6, 2020 Author Share Posted February 6, 2020 Hi I have tried sending httprequest as shown in the following using UniHTMLFrame. If I use a gateway the message is sent correctly, however if it sent directly it only sends "Option" issue with Cross-Origin Resource Sharing (CORS). How is possible to overcome this and not use a gateway? Thanks <script> var request = new XMLHttpRequest(); var HTTPServerIP = "192.168.1.10"; var HTTPServerPORT = "8765"; var HTTPServerVersion = "V6"; var HTTPServerURL = "http://" + HTTPServerIP + ":" + HTTPServerPORT + "/API2/CITYGUIDE/" + HTTPServerVersion + "/"; var ContentType = "application/json"; var versionID = "v5"; request.open('POST', HTTPServerURL); request.setRequestHeader("Content-Type", ContentType); request.setRequestHeader("authorization", 'BASIC TWFyYW5keTpDaXR5R3VpZGU='); request.responseType = 'json' request.send(JSON.stringify({ "command":"Testing","Message":"This is test message" })) </script> Quote Link to comment Share on other sites More sharing options...
Ron Posted February 7, 2020 Share Posted February 7, 2020 If you are making an http request from the client (which you do when you use JS, as all JS runs in the browser client) then you can only communicate with the local computer through CORS, and the local webserver must be configured to accept such requests. If you want to communicate to the outside world, you have to do it from the server side, and that is straightforward using e.g. idHTTP and doing a simple http get request. Example of JS call to local webserver using CORS UniSession.AddJS('$.get("http://127.0.0.1:'+uniMainModule.corsPort+'?event='+inttostr(EventID)+'&op='+uniMainModule.operator+'", function( data ){' + ' ajaxRequest(TransactionForm.form, ["cashRegisterEvent"], { response : data }); '+ ' }); '); Apache set up for CORS in httpd.conf <VirtualHost *:80> DocumentRoot "c:\program files (x86)\cashreg\apache22\htdocs" Header set Access-Control-Allow-Origin "*" </VirtualHost> IndyHTTPServer set up for CORS if sameText('127.0.0.1', ARequestInfo.RemoteIP) and (ARequestInfo.CommandType=hcGet) and (length(aRequestInfo.Params.text)>0) then begin AResponseInfo.CustomHeaders.AddValue('Access-Control-Allow-Origin', '*'); EventIDStr:=aRequestInfo.Params[0]; Quote Link to comment Share on other sites More sharing options...
MOGSY Posted February 7, 2020 Author Share Posted February 7, 2020 Thank you very much Ron what are "uniMainModule.corsPort", "EventID" and "uniMainModule.operator" ? UniSession.AddJS('$.get("http://127.0.0.1:'+uniMainModule.corsPort+'?event='+inttostr(EventID)+'&op='+uniMainModule.operator+'", function( data ){' + ' ajaxRequest(TransactionForm.form, ["cashRegisterEvent"], { response : data }); '+ ' }); '); Quote Link to comment Share on other sites More sharing options...
Ron Posted July 15, 2021 Share Posted July 15, 2021 Those are just dummy variables, and you only need the port set if you are not using port 80, which it then defaults to over http. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.