EldoS | Feel safer!

Software components for data protection, secure storage and transfer

HTTPS Sample

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#18811
Posted: 01/24/2012 13:48:26
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Is there some simple HTTPS post example somewhere? All I want to do is send a string (some xml) and receive a string back. The HttpsClient.post and Get are connecting to my target server correctly and returning a response - I cannot see where I add the content for the post
#18812
Posted: 01/24/2012 14:00:09
by Eugene Mayevski (EldoS Corp.)

POST method has several overloads including the one accepting a Stream (and you can save a string into MemoryStream). The problem with a sample for POST is that there must also be a server-side module, and practice shows that a PHP script is too complicated for many users to understand.


Sincerely yours
Eugene Mayevski
#18813
Posted: 01/24/2012 15:08:07
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Thank you.
I create the following code to use the file stream.
It is now returning a response fr om the server.
However the response is not correct

Here is my Delphi2007 code
Code
procedure TFrmMain.Button1Click(Sender: TObject);
var
  MEMO, MS, Source: TMemoryStream;
  vrequest,vresponse,vurl: string;
  HTTPS : TElHTTPSClient;
  auxSL: TStringList;
begin
  vurl := CbProtocol.Text + '://' + EdHost.Text + ':' + EdPort.Text + EdPath.Text;
  try
    HTTPS := TElHTTPSClient.Create(nil);
    Source := TMemoryStream.Create;
    MS := TMemoryStream.Create;
    MS.Position := 0;
    if HTTPS.Active then HTTPS.SSLEnabled := false;
    HTTPS.OutputStream := MS;
    HTTPS.PreferKeepAlive := true;
    HTTPS.UseCompression := true;
    HTTPS.SocketTimeout := 0;
    HTTPS.RequestParameters.AcceptCharset :='text/xml;charset=utf8';
    HTTPS.RequestParameters.Accept :='text/xml;charset=utf8';


    //HTTPS.OnCertificateValidate := ClientCertificateValidate;
    //HTTPS.OnCertificateNeededEx := ClientCertificateNeededEx;

    vrequest := 'OrderXml=' + memo1.text;
    ShowMessage(vrequest);
    Source.Write(Pointer(vrequest)^, Length(vrequest));
    HTTPS.Post(vurl, Source, False);
    ShowMessage('Total send bytes ' +IntToStr( HTTPS.TotalBytesSent)) ;
    ShowMessage('Total bytes receive ' +IntToStr( HTTPS.TotalBytesReceived)) ;
    showmessage(inttostr(MS.Size));
    auxSL := TStringList.Create;
    MS.Position := 0;
    auxSL.LoadFromStream(MS);
    vresponse := auxSL.Text;
    auxSL.Free;
    ShowMessage(vresponse);
    memo2.Lines.LoadFromStream(MS);
  finally
    FreeAndNil(MS);
    FreeAndNil(Source);
    FreeAndNil(HTTPS);
  end;
end;

It should return some XML and instead is returning a blank page.

They have a simple test html page wh ere I posted the same XML. It returns the correct XML response.
Any suggestions appreciated
#18815
Posted: 01/24/2012 23:59:12
by Eugene Mayevski (EldoS Corp.)

1) Please use CODE tag/button to mark the code and make it readable in the forum
2) You don't reset Source stream position before passing it to HTTPS client. You must set position of Source stream to position from which you want to start. Instead, for MS setting Position to 0 makes no sense as it is 0 by default.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 1819 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!