RTC Forums

Subscription => Support => Topic started by: Nanosystems on September 04, 2013, 02:23:19 PM



Title: Dummy question: read POST data from onDataReceived event
Post by: Nanosystems on September 04, 2013, 02:23:19 PM
Hi, i have a client calling my server posting 2 parameters inside POST data (not querystring), and i need to read it. Now here how my code works:

Code:
procedure TForm6.RtcDataProvider1DataReceived(Sender: TRtcConnection);
var
    vsFileName : string; //(1)
    viFileSize : integer;
    readString : string;
begin
  readString := (sender as TRtcConnection).read();
  with TRtcDataServer(Sender) do //(2)
    if Request.Complete then
    begin
      write('Test1: ' + Request.Info['param1'] + ', Test2: ' + Request.Params.Value['param1'] + ', readString: ' + readString);
    end;
end;

it's just an edited example! I can read the full POST data inside readString, but i don't have an object to call the single parameters, something like "myObject['param1']".
i tried to read the "param1" parameter in some ways but i always got an empty string, those in the code are just 2 of my tries.

Does RealThinClient provide some already working object to encapsulate and read POST data?


Title: Re: Dummy question: read POST data from onDataReceived event
Post by: Kevin Powick on September 04, 2013, 02:44:02 PM
Just going by memory, but I think that all you need to do is populate the Params.

See added line in modified code sample below.

Code:
procedure TForm6.RtcDataProvider1DataReceived(Sender: TRtcConnection);
var
    vsFileName : string;
    viFileSize : integer;
    readString : string;
begin
  readString := (sender as TRtcConnection).read();
  with TRtcDataServer(Sender) do
    if Request.Complete then
    begin
      Request.Params.AddText(readString); // <--- LOAD PARAMS  
      write('Test1: ' + Request.Params.Value['param1'] + ', readString: ' + readString);
    end;
end;


Title: Re: Dummy question: read POST data from onDataReceived event
Post by: Nanosystems on September 04, 2013, 05:00:26 PM
thank you, it works flawlessly :)