Search code examples
delphidelphi-xedevart

Delphi Devart SecureBridge POST Request


I am using the trial version of DevArt's SecureBridge product. I am trying to process POST, but somehow I could not print the request data.

XML:

<test>
<a>test1</a>
<b>test2</b>
</test>

Delphi:

  ScHttpWebRequest1.Method := rmPOST;
  ScHttpWebRequest1.ContentType := 'text/xml';
  ScHttpWebRequest1.RequestUri := 'https://test.com/api';
  ScHttpWebRequest1.KeepAlive := True;
  ScHttpWebRequest1.ContentLength := Length(XML);
  ScHttpWebRequest1.WriteBuffer(pAnsiChar(XML), 0, Length(XML)); ///I think I'm making a mistake here.
  ShowMessage(ScHttpWebRequest1.GetResponse.ReadAsString);

I have reviewed the documents, but there is a feature called RequestStream. This feature was not available in the version I downloaded. I think WriteBuffer is used instead or different. all I want to do is request a POST with XML content on the relevant site. How can I do it?

Thanks.


Solution

  • Here's a chunk of code that has worked for me:

    var
     Response: TScHttpWebResponse;
     ResponseStr: string;
     buf: TBytes;
    begin
      ScHttpWebRequest1.Method := rmPOST;
      ScHttpWebRequest1.ContentType := 'text/xml';
      ScHttpWebRequest1.RequestUri := 'https://test.com/api';
      ScHttpWebRequest1.KeepAlive := True;
    
       buf := TEncoding.UTF8.GetBytes(xml);
       ScHttpWebRequest1.ContentLength := Length(buf);
       ScHttpWebRequest1.WriteBuffer(buf);
       Response:=ScHttpWebRequest1.GetResponse;
       ResponseStr:=Response.ReadAsString;
    end;