RTC Forums
April 25, 2024, 11:49:31 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: 1 [2]
  Print  
Author Topic: sending a XML-file back with a TRctHTTPserver  (Read 16126 times)
Henk vd Boogaard
RTC Expired
*
Posts: 24


« Reply #15 on: September 05, 2018, 11:01:39 AM »

First, I indeed posted my reply in the wrong place.
I was looking there for you answer for my xml questions, but that program you advised me to work with a rtcFunction and that program works fine.
However now I must use xml and I am struggling again.
I apricate very much that you help so good.
===========================
I altered the code as you suggested and made also the last additions.
I post here the last bit.
Only I get an error on:
RtcDataRequest1.PostMethod('POST', XML_string);
// <--- GIVES A COMPILE ERROR 'THERE IS NO OVERLOADED VERSION OF THIS'

Also can you point me to a good example to implement StreamSec2 for the RtcDataRequest for that must be in HTTPS.

Thanks
Henk
====================
procedure TWork.RtcDataProvider1DataReceived(Sender: TRtcConnection);
var
  RecvContent, ResultText, StatusText: rtcString;
begin
  with Sender as TRtcDataServer do
  begin
    if Request.Complete then
    begin
      RecvContent := Sender.Read;
      TransactionID_str := Request.Query['transactionid'];
      if DoDebug then
        Memo1.Text := Memo1.Text + READ;
      Memo1.Lines.Add('ID=' + TransactionID_str);
      try
        IDealRecNr := StrToInt(TransactionID_str);
      except
        on E: Exception do
          if DoDebug then
            Memo1.Lines.Add('Fout bij vertalen recordnummer van parameter : ' + E.Message);
      end;

      with RtcDataRequest1 do
      begin
        Request.FileName := '/' + TransactionID_str;
        CoInitialize(nil);
        // nu in database Huurovereenkomst controleren - indien OK dan VerstuurHTML:

        // maak XML-file:
        Exportfilenaam := 'IDeal_' + IntToStr(IDealRecNr) + '.XML';
        XMLDoc1.Active := false;
        XMLDoc1.Xml.Text := '';
        XMLDoc1.Active := true;
        XMLDoc1.Encoding := 'UTF-8';
        XMLDoc1.AddChild('Pricat', 'http://www.ean.nl');
        XMLDoc1.DocumentElement := XMLDoc1.CreateNode('status');
        XMLDoc1.DocumentElement.Attributes['ua'] := 'RTC Library)';

        // merchant
        iNode_Merchant := XMLDoc1.DocumentElement.AddChild('merchant');
        iChild := iNode_Merchant.AddChild('account');
        iChild.Text := DM1.nxT_algpar.FieldByName('IDeal_account').AsString;
        iChild := iNode_Merchant.AddChild('site_id');
        iChild.Text := DM1.nxT_algpar.FieldByName('IDeal_site_id').AsString;
        iChild := iNode_Merchant.AddChild('site_secure_code');
        iChild.Text := DM1.nxT_algpar.FieldByName('IDeal_site_secure_id').AsString;

        // transaction
        iNodeTransaction := XMLDoc1.DocumentElement.AddChild('transaction');
        iChild := iNodeTransaction.AddChild('id');
        iChild.Text := IntToStr(IDealRecNr);
        // bestand maken:
        if DoDebug then
          XMLDoc1.SaveToFile(DM1.XML_Dir + Exportfilenaam);

        XMLDoc1.SaveToXML(XML_string);
        // now get the information
        RtcHttpClient1.ServerAddr := DM1.SiteURL;
        RtcHttpClient1.ServerPort := IntToStr(DM1.SitePort);
        // Post the request with 'POST' :
        RtcDataRequest1.PostMethod('POST', XML_string); // <--- GIVES A COMPILE ERROR 'THERE IS NO OVERLOADED VERSION OF THIS'
        WaitForCompletion;

        XMLDoc1.Active := false;
        XMLDoc2.Active := false;
        XMLDoc2.LoadFromXML(RecvContent); // Response is an XML file
        XMLDoc2.Active := true;
        // now get the information from XMLdoc2:
        ResultText := XMLDoc2.DocumentElement.Attributes['result'];
        iNodeEwallet := XMLDoc2.DocumentElement.ChildNodes.FindNode('ewallet');
        iNodeStatus := iNodeEwallet.ChildNodes.FindNode('status');
        if Assigned(iNodeStatus) then
          StatusText := iNodeStatus.Text;
        // database bijwerken:
        if DM1.nxT_IDealRecords.FindKey([IDealRecNr]) then
        begin
          if Uppercase(ResultText) = 'OK' then
          begin
            DM1.nxT_IDealRecords.Edit;
            DM1.nxT_IDealRecords.FieldByName('StatusOntvangen').AsBoolean := true;
            DM1.nxT_IDealRecords.FieldByName('Status').AsString := StatusText;
            if Uppercase(StatusText) = 'COMPLETED' then
              DM1.nxT_IDealRecords.FieldByName('BetalingOK').AsBoolean := true;
            DM1.nxT_IDealRecords.Post;
          end
          else
          begin
            DM1.nxT_IDealRecords.Edit;
            DM1.nxT_IDealRecords.FieldByName('StatusOntvangen').AsBoolean := false;
            DM1.nxT_IDealRecords.FieldByName('Status').AsString := StatusText;
            DM1.nxT_IDealRecords.FieldByName('Foutkode').AsString := ResultText;
            DM1.nxT_IDealRecords.Post;
          end;

        end
        else if DoDebug then
          Memo1.Lines.Add('Kan IDealrecord niet vinden');
        // bewaren als laatste zodat eerst de database wordt bijgewerkt
        if DoDebug then
          XMLDoc2.SaveToFile(DM1.XML_Dir + DateTimeToStr(now) + 'result' + IntToStr(IDealRecNr) + '.xml');
        CoUninitialize;
      end;
    end;
  end;
end;

Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #16 on: September 05, 2018, 11:18:30 AM »

Oops  Embarrassed Sorry, my mistake. You need the "Write" method on the "RtcDataRequest" component (not on the "RtcHttpClient" component) to prepare the request content body which you want to send, then you can use "PostMethod" to post your request without the need to implement the "OnBeginRequest" and "OnDataSent" events for sending the request headers and/or content out.

In other words, you need ...

RtcDataRequest1.Write(XML_string);
RtcDataRequest1.PostMethod('POST');

As for your StreamSec question, please contact the StreamSec component vendor with ANY questions you may have about using their components.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #17 on: September 05, 2018, 11:30:23 AM »

I also see that you've misunderstood my intention with the "RecvContent" variable. It has to be a global variable or a variable of your main class (not local to any event) and you need to use the "Sender.Read" method inside the "OnDataReiceved" event of your RtcDataRequest component if you want the response from your external Server (received by your RtcDataRequest component, which is attached to your RtcHttpClient companent).

So ... what you did now by calling "RecvContent:=Read" inside your "RtcDataProviderDataReceived" event gives you the request content which your Server has received from your inbound Client and NOT the response content body sent to you from your external Server.

On one side, you have your Server communicating with Clients through "RtcHttpServer" and the linked "RtcDataProvider" component (using events attached to these components), while on the other side you have the same process communicating with another external Server by using the "RtcHttpClient" and "RtcDataRequest" (using events on these components). These are two completely separate communication channels, each with its own request and response data, so need to watch out and sure you do NOT mix them up! It's a HUGE difference where and on which components you call "Read" and "Write"!!!
Logged
Henk vd Boogaard
RTC Expired
*
Posts: 24


« Reply #18 on: September 10, 2018, 11:33:17 AM »

Hi Danijel

Are you sure that sending with:
RtcDataRequest1.Write(XML_string);
RtcDataRequest1.PostMethod('POST');
is working within the procedure RtcDataProvider1DataReceived(Sender: TRtcConnection);?

It seems there is nothing sent out.

Can I email you a link so you can download my program for testing?


Henk van den Boogaard
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #19 on: September 10, 2018, 01:03:42 PM »

Remove the "WriteHeader" call from your "RtcDataRequest1BeginRequest" event. That call makes it impossible to send out the content you've prepared with the "RtcDataRequest1.Write(XML_string)".

Why? Because you are NOT setting the "Request.ContentLength", which HAS TO BE SET manually before calling "WriteHeader". If you just call "WriteHeader" but have NOT set the "Request.ContentLength" before, you will end up sending a request with NO CONTENT BODY.
Logged
Henk vd Boogaard
RTC Expired
*
Posts: 24


« Reply #20 on: September 10, 2018, 04:15:42 PM »

Hi Danijel,

How can I see/get the complete message before it is being POST?
So I can check it of it is what MSP want.


Henk
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #21 on: September 10, 2018, 04:46:25 PM »

Normally, whatever you prepare will be sent out, so there are no events or methods on RTC components which would allow you to double-check what was prepared before it actually goes out, but ... you should be able to use
external Network Traffic monitoring tools like Wireshark to check what is REALLY being sent and received:
https://www.wireshark.org/
Logged
Henk vd Boogaard
RTC Expired
*
Posts: 24


« Reply #22 on: September 11, 2018, 02:02:04 PM »

Hi Danijel

I have the program working.
So I am very happy you and Henrick (StreamSec) helped me.
Only one problem is now that on my pc is works fine but on the server (Windows Server 2016) it seems that the outgoing port 443 is blocked.
But they are investigate that.

Thanks
Henk van den Boogaard
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #23 on: September 11, 2018, 06:39:03 PM »

Glad to know it's working. Thanks for your feedback.
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.029 seconds with 16 queries.