RTC Forums
November 25, 2024, 05:09:45 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: site not responding  (Read 6540 times)
Henk vd Boogaard
RTC Expired
*
Posts: 24


« on: October 29, 2018, 01:11:57 PM »

Why does not respond the site after I sent a message?
------------------------code--------------------------------
unit Unit15;
{$include rtcDeploy.inc}
{$include rtcDefs.inc}
{$DEFINE StreamSecII}
{$DEFINE RTC_DEBUG}

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, rtcConn, rtcDataCli, rtcHttpCli, rtcSystem, rtcInfo, Vcl.StdCtrls,
  RtcSSecTest, rtcDataSrv, rtcHttpSrv;

type
  TForm15 = class(TForm)
    RtcDataRequest1: TRtcDataRequest;
    RtcHttpClient1: TRtcHttpClient;
    Memo1: TMemo;
    Button1: TButton;
    procedure RtcDataRequest1DataReceived(Sender: TRtcConnection);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RtcHttpClient1ResponseReject(Sender: TRtcConnection);
  private
    { Private declarations }
    RecvContent: rtcString;
    XML_string: rtcString;
  public
    { Public declarations }
  end;

var
  Form15: TForm15;

implementation

{$R *.dfm}

procedure TForm15.Button1Click(Sender: TObject);
begin
  RtcDataRequest1.Request.Clear;
  XML_string := 'testen';
  RtcHttpClient1.ServerAddr := 'https://webhook.site/f8afd984-2151-4332-84f7-ceab0d6480fd';
  RtcHttpClient1.ServerPort := '443';
  RtcDataRequest1.Request.FileName := '/test/';

  RtcDataRequest1.Request.Host := RtcHttpClient1.ServerAddr;
  RtcDataRequest1.Write(XML_string);
  RtcDataRequest1.Request.ContentLength := Length(XML_string);
  try
    // Post the request with 'POST' :
    RtcDataRequest1.PostMethod('POST');
    RtcDataRequest1.WaitForCompletion;
  except
    on E: Exception do
      Memo1.Lines.Add('Error with getting information by MSP : ' + E.Message)
  end;
end;

procedure TForm15.FormCreate(Sender: TObject);
begin
  // if the Server is using an expired certificate: }
  AllowExpiredCertificates(true);

  // If we do not have a root certificate on the client,
  // we will use a HACK to allow the client to work with ANY Server: }
  BeGullableAndTrustAnythingSentToYou(true);

  { This is a simple DEMO, so we will accept our "locahost" certificate,
    even if our test Server is running on a remote PC and not locally: }
  AddCertificateNameMap('*', 'localhost');

    AddClientRootCertFile('C:\DigiCertGlobalRootCA.cer');
  AddClientPFXFile('C:\client.pfx', 'abc');
  RtcHttpClient1.CryptPlugin := GetClientCryptPlugin;
end;

procedure TForm15.RtcDataRequest1DataReceived(Sender: TRtcConnection);
begin
  with TRtcDataClient(Sender) do
  begin
    if Response.Started then
      if Response.Done then
        RecvContent := Sender.Read;

    Memo1.Lines.Add('Response: ' + RecvContent);
    Memo1.Lines.Add('Status code: ' + IntToStr(Response.StatusCode));
    Memo1.Lines.Add('Status text:' + Response.StatusText);
    Memo1.Lines.Add('ALL Headers:');
    Memo1.Lines.Add(Response.HeaderText);
    Memo1.Lines.Add('Content Length:');
    Memo1.Lines.Add(IntToStr(Response.ContentLength));
    Memo1.Lines.Add('Content body:');
    Memo1.Lines.Add('START >');
  end; { Could be executed more than once,  depending on the content size }
end;

procedure TForm15.RtcHttpClient1ResponseReject(Sender: TRtcConnection);
begin
   showmessage('error in response');
end;

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


« Reply #1 on: October 29, 2018, 02:44:42 PM »

Unless you are receiving a very short response that fits into a single TCP/IP packet, you will either get "Response.Started=TRUE" (when the first packet arrives) or "Response.Done=TRUE" (after the last packet arrives), but NOT both at the same time.

IOW, your check ...

if Response.Started then
   if Response.Done then
       RecvContent := Sender.Read;

... most likely means that the "Sender.Read" line is never being called for any response that has more than a few bytes of data.

In short, ONLY check for "Response.Done" before calling "Sender.Read" if you want to wait for a complete response to arrive before you read it as a whole.
Logged
Henk vd Boogaard
RTC Expired
*
Posts: 24


« Reply #2 on: October 29, 2018, 02:57:35 PM »

Hi Danijel,

I think I did not clearly explained my question.

The Site Webhook.site is for testing what you sent.
I have still problems with the communication with the MultiSafePay site.
So I made a test program to see what I sent out.
However the site seems to get no info from me.

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


« Reply #3 on: October 29, 2018, 02:59:48 PM »

Also ... the "ServerAddr" property should ONLY contain the IP Address. IOW, this line ...

RtcHttpClient1.ServerAddr := 'https://webhook.site/f8afd984-2151-4332-84f7-ceab0d6480fd';

... should look like this ...

RtcHttpClient1.ServerAddr := 'webhook.site';

And ... if your "ServerAddr" value is an indication of what you actually wanted, then you also need to move the URI part of your address to the "Request.URI" of "Request.FileName" property, for example ...

  RtcDataRequest1.Request.FileName := '/f8afd984-2151-4332-84f7-ceab0d6480fd/test/';

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


« Reply #4 on: October 29, 2018, 03:01:24 PM »

The site can't get any info from you if you don't set components properties and implement the events correctly.

Check my two responses above and see if you can fix your code.

Also check all other components properties.

PS. You might want to re-visit Quick Start lessons, because you are making beginner mistakes.
Logged
Pages: [1]
  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.028 seconds with 17 queries.