EldoS | Feel safer!

Software components for data protection, secure storage and transfer

HTTPS Sample

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
Posted: 01/24/2012 14:00:09
by Eugene Mayevski (Team)

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
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
procedure TFrmMain.Button1Click(Sender: TObject);
  MEMO, MS, Source: TMemoryStream;
  vrequest,vresponse,vurl: string;
  auxSL: TStringList;
  vurl := CbProtocol.Text + '://' + EdHost.Text + ':' + EdPort.Text + EdPath.Text;
    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;
    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)) ;
    auxSL := TStringList.Create;
    MS.Position := 0;
    vresponse := auxSL.Text;

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
Posted: 01/24/2012 23:59:12
by Eugene Mayevski (Team)

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



Topic viewed 1932 times

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


Back to top

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

Got it!