Jump to content

How to receive POST / GET Requests on UniGUI Server?


Recommended Posts

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


Receiving comand is like

procedure TMainForm.IdHTTPServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);

if ARequestInfo.Params.Values['MyComand']='DoSomethingNow' then

Link to comment
Share on other sites

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

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

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

  • 3 months later...

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

  • 4 months later...

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 >

    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 ; <- ok
rs := 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;


thanks for your helps !! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...