RTC Forums
April 19, 2024, 04:34:05 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: not getting 'OK' in browser  (Read 4222 times)
Henk vd Boogaard
RTC Expired
*
Posts: 24


« on: October 26, 2018, 08:47:16 AM »

Why do I not get 'OK' but "ERR_EMPTY_RESPONSE" in Chrome?

procedure TWork.RtcDataProvider1DataReceived(Sender: TRtcConnection);
var
  ResultText, StatusText: rtcString;
begin
  with Sender as TRtcDataServer do
  begin
    if Request.Complete then
    begin
      Write('OK');
      TransactionID_str := Request.Query['transactionid'];
      if DoDebug then
        Memo1.Text := Memo1.Text + '  received: ' + Request.Params.Text;
      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);
        // make 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:
        XMLDoc1.SaveToXML(XML_string);
        if DoDebug then
        begin
          XMLDoc1.SaveToFile(DM1.XML_Dir + Exportfilenaam);
          Memo1.Lines.Add('URL that is sent to MSP:');
          Memo1.Lines.Add(XML_string);
        end;

        // now get the information
        if DM1.TestString = '1' then
        begin
          RtcHttpClient1.ServerAddr := DM1.SiteURL; // 'api.MultiSafepay.com'
          RtcHttpClient1.ServerPort := IntToStr(DM1.SitePort);
          RtcDataRequest1.Request.FileName := '/ewx/';
          RtcDataRequest1.Request.Host := DM1.SiteURL; // 'api.MultiSafepay.com'
          RtcDataRequest1.Write(XML_string);
          RtcDataRequest1.Request.ContentLength := Length(XML_string);
        end;

        // if DM1.TestString = '2' then
        // begin
        // RtcHttpClient1.ServerAddr := 'http://localhost:22333/ewx/';
        // RtcHttpClient1.ServerPort := '80'; // IntToStr(443); // 443
        // // RtcDataRequest1.Request.FileName := '/ewx';
        // RtcDataRequest1.Request.Clear;
        // RtcDataRequest1.Request.Host := 'http://localhost:22333/ewx/';
        // RtcDataRequest1.Write(XML_string);
        // RtcDataRequest1.Request.ContentLength := Length(XML_string);
        // end;

        try
          // Post the request with 'POST' :
          RtcDataRequest1.PostMethod('POST');
          WaitForCompletion;
        except
          on E: Exception do
            if DoDebug then
              Memo1.Lines.Add('Error with getting information by MSP : ' + E.Message)
        end;
        XMLDoc1.Active := false;
        XMLDoc2.Active := false;
        if RecvContent <> '' then
        begin
          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;
          // if the received message is OK then complete the database:
          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
          begin
            DatumTijdString := U_Henk_Extra_Procs_Funcs.RemoveIllegalChars(DateTimeToStr(now));
            XMLDoc2.SaveToFile(DM1.XML_Dir + DatumTijdString + '_retour_xml_van_MSP' + IntToStr(IDealRecNr) + '.xml');
          end;
        end
        else // if RecvContent <> ''
          Memo1.Lines.Add('Ontvangen van MSP: ' + RecvContent);
        CoUninitialize;
      end;
    end;
  end;
end;

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


« Reply #1 on: October 26, 2018, 08:54:51 AM »

https://www.google.com/search?q=chrome+err_empty_response
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #2 on: October 26, 2018, 09:41:51 AM »

Btw ... some Browsers require that you specify the Content-Type in the HTTP response headers, or they won't show it (or display it incorrectly). For example, when sending back a response containing HTML, you should set the Content-Type header to 'text/html' ...

Sender.Response.ContentType='text/html';
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.026 seconds with 16 queries.