elGringo Posted September 2, 2016 Share Posted September 2, 2016 I know about Ajax in UniGUI but I want to send usual POST message from another app - but don't know how to receive and handle it on the UniServer? All examples in Demos about Ajax. Does anyone experienced in that question? Link to comment Share on other sites More sharing options...
elGringo Posted September 2, 2016 Author Share Posted September 2, 2016 For ex. like in PHP echo "Param1 = ",$_POST["param1"]; echo "Param2 = ",$_POST["param2"]; is there is something the same in UniGUI? Link to comment Share on other sites More sharing options...
rgreat Posted September 2, 2016 Share Posted September 2, 2016 UniApplication.Parameters.Values['param1'] Link to comment Share on other sites More sharing options...
elGringo Posted September 2, 2016 Author Share Posted September 2, 2016 Thank you ! does it also work for POST requests, in demos this code works for GET Requests UniButton1.Caption:=UniApplication.Parameters.Values['Button']; UniEdit1.Text:=UniApplication.Parameters.Values['Edit']; I will test it anyway Link to comment Share on other sites More sharing options...
elGringo Posted September 2, 2016 Author Share Posted September 2, 2016 Test is over. Result is following 1. UniApplication.Parameters.Values['param1'] works only when update page with params in URL like http://localhost:8077/?button=BB&edit=AA For my task that is not Ok. 2. I was need to send some comand from external app. For that I used HTTP protocol and idHTTP, idHTTPServer components on UniGUI Port for idHTTPServer I changed for 82 - don't know why but on 80 Port idHTTP couldn't bind sockets. And i'm not sure but maybe it is better to put idHTTPServer in ServerModule and not to Main... - will test it later Sending comand is like Params:=TStringList.Create; Params.Add('MyComand=DoSomethingNow'); HtmlResult:=IdHTTP.Post('http://localhost:82/',Params); FreeAndNil(Params); Receiving comand is like procedure TMainForm.IdHTTPServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); begin if ARequestInfo.Params.Values['MyComand']='DoSomethingNow' then ShowMessage('ComandReceived'); end; Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 And i'm not sure but maybe it is better to put idHTTPServer in ServerModule and not to Main... - will test it later idHTTPServer in MainForm or MainModule results in one server per session. And each server neeeds an own port. Just use UniServerModule->OnHTTPCommand. Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 Oliver - thank you for advice! I will check it today. Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 Does UniServer contains HTTPServer and on which port ? 80? Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 UniGui creates a web app, so there must be a http server. Port is the same as your app. Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 Clear! Will test it anyway And FTP? For the moment i use Indy FTP Server in Separate EXE I'm writing VCL program that will -Send POST Request to Start FTP Server on Server Machine if not Started (using HTTP Protocol) -Send Files in threads -Get Approval that files on the ServerMachine Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 I would use HTTP POST instead of a FTP server for uploading files. Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 why? is it more modern? Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 why? is it more modern? YES. And you need only UniGUI. Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 or no need to create FTP Server, just use UniGUI instead? In neighbor topic http://forums.unigui.com/index.php?/topic/7131-unigui-as-ftp-server-possible/ Zilav showed me an example but i doubt about following things -how it will work with big files like 2GB -encoded multipart data stream - for the moment I didn't work with it. Is it Stable, Reliable ? Encoding and Decoding doesn't create any Distortion? Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 I think cloud services (onedrive, dropbox, ...) do the same in their APIs... Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 Sorry. I see onedrive uploads in parts, if file is bigger than 100 MB: https://dev.onedrive.com/items/upload_large_files.htm Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 That's clear and you absolutely right. I would use clouds if my task would allow it because it is simple reliable and convenient. But my program will be installed on Windows Servers and file storage should be close to DB engine. So i am in process and thank you very much for the answers, Oliver!!! Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 And idea to divide big files looks very well. Need to try it... Link to comment Share on other sites More sharing options...
elGringo Posted September 3, 2016 Author Share Posted September 3, 2016 Or you just meant that they use HTTP Protocol? If so - yes that is strong argument. Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 3, 2016 Share Posted September 3, 2016 Or you just meant that they use HTTP Protocol? If so - yes that is strong argument. Yes. It is the modern way... Link to comment Share on other sites More sharing options...
Ron Posted December 31, 2016 Share Posted December 31, 2016 There are a number of ways to get a file to unigui, first some acting as server. 1. Use the built-in indy HTTP server, and the uniServerModule events OnHTTPCommand and OnHTTPDocument. Then you have to encode the file before you send it. There is no point in setting up an extra HTTP server, as unigui contains one already. 2. Use an indy TCP server in the uniServerModule, and a TCPClient in the VCL app. This is by far the easiest and most straightforward way, use TCPClient.IOHandler.writeFile on the client side and ReadStream on the server side. 3. Use an FTP server in the uniServerModule, and an FTP client on the VCL side. FTP is a bit more complex than TCP, but also provides more options. 4. Use an SMTP server and send the file as a mail attachment, or any other protocol. Of all these protocols, TCP is the easiest one to set up for simple text/binary file transfer. Of course the TCP server would have to run on a different port than the built-in unigui indy webserver. Historically, I think it is safe to say that FTP and TCP have been the primary protocols for binary internet transfer, especially on upload, with HTTP Post gradually taking a bigger part of that pie as working encoding solutions have been worked out. The reason for the increased use of HTTP Post for binary transfer, is the ability to then use the webserver which is already there, not having to think about opening extra ports in the firewalls for another listening server, and so on. The challenge with HTTP Post file transfer is the encoding of the data, and also to some degree the transfer process. With TCP or FTP you do not need to think very much about that. If anyone has tested and working code for HTTP Post of binary files using indy, please post it here. You could also get a file to unigui server, with unigui acting as client. Just send a HTTP command (i.e. including the link) to trigger the unigui server to initiate the download of the file, which it then does, moves it to someplace and then generates a download link. This of course assumes the file is already available online. Link to comment Share on other sites More sharing options...
david600320@hotmail.com Posted May 22, 2017 Share Posted May 22, 2017 Hi !! Q. How can i get a Params.Values[] ? - I shoud get a value for searching . - URLFrame , ajax( jQuery) , Unigui Stand alone Server . Delphi XE2 < HTML in UNIFrame > $.ajax({ url : '/test?username=1111&password=2222' , type : "POST", async : false, data : formData , // <--- correct ? var formData = {}; formData['search_key'] = search_key ; /* condition for searching */ dataType : "text", // <--- correct ? success : function(response) { console.log( response ) ;json_obj = response ; }, error : function(errorData,error){ console.log( 'errorData=' + errorData ) ; }}); <Server side> if ARequestInfo.URI = '/test' then begin//** I can't get params.values['search_me']rs := '' ;rs := rs + ' ARequestInfo.Document = ' + ARequestInfo.Document ; <- okrs := rs + ' ARequestInfo.Params.Values search_key=' + ARequestInfo.Params.Values['search_key'] ; <- nothing !!StrToFile( 'log.txt' , rs ) ;AResponseInfo.ContentType := 'text/html';AResponseInfo.ContentText := cResponseText ;Handled := true;end; test_urlframe_ajax.zip thanks for your helps !! Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted May 22, 2017 Administrators Share Posted May 22, 2017 Hi, In your test case no prameter named "search_me" is sent. Link to comment Share on other sites More sharing options...
david600320@hotmail.com Posted May 22, 2017 Share Posted May 22, 2017 I will check again . Thanks for your reply !! Link to comment Share on other sites More sharing options...
david600320@hotmail.com Posted May 22, 2017 Share Posted May 22, 2017 Hi again !! - That's my fault - ( function StrToFile() has a problem not to show string exactly ); *** URLFrame is so much better than I thought it would be **** Many thanks for Farshad Mohajeri !! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now