EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElHTTPSClient Help

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.
#15993
Posted: 03/07/2011 11:30:12
by Luis Arenal (Standard support level)
Joined: 05/10/2006
Posts: 9

Hi.-

Trying to use TElHTTPSClient instead of TIdHTTP. Using certificates.
but getting a server error "Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog"
Am I missing some options? First test, please help.

Code
var
  lHttps: TElHTTPSClient;
  msSource, msOutput: TMemoryStream;
  lSOAPMsg: string;
  slAux: TStringList;

  msOutput := TMemoryStream.Create;

  lHttps := TElHTTPSClient.Create(nil);
  lHttps.SSLEnabled := True;
  lHttps.OutputStream := msOutput;
  lHttps.PreferKeepAlive := True;
  lHttps.UseCompression := True;
  lHttps.SocketTimeout := 0;
  lHttps.RequestParameters.AcceptCharset :='text/xml;charset=utf8';
  lHttps.RequestParameters.Accept :='text/xml;charset=utf8';
  lHttps.RequestParameters.ContentType := 'text/xml';
  lHttps.OnCertificateNeededEx := HttpsCertificateNeededEx;
  lHttps.OnCertificateValidate := HttpsCertificateValidate;

  lSOAPMsg := ...SOAP Msg...

  msSource := TMemoryStream.Create();
  msSource.Write(Pointer(lSOAPMsg)^, Length(lSOAPMsg));

  lHttps.Post(UrlWs, msSource, False);

  msOutput.Position := 0;
  slAux := TStringList.Create;
  slAux.LoadFromStream(msOutput);
  lSOAPMsg := slAux.Text;
  slAux.Free;


Note:
with Indy+OpenSSL I do this without problems.
SoapMsg is sent and response is received Ok.
Same SoapMsg.

Code
var
  lHttp: TIdHTTP;
  lSSLIOHandler: TIdSSLIOHandlerSocketOpenSSL;
  lSOAPMsg: string;
  msSource: TMemoryStream;
  ssResponse: TStringStream;

lHttp := TIdHTTP.Create;
lSSLIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create;

lHttp.Request.ContentType := 'text/xml;charset=utf8';
lHttp.Request.CustomHeaders.Add('Connection: Keep-Alive');
lHttp.ReadTimeout := 20000;
lHttp.IOHandler := lSSLIOHandler;

lSSLIOHandler.SSLOptions.CertFile := CertFilePEM;
lSSLIOHandler.SSLOptions.KeyFile := KeyFilePEM;
lSSLIOHandler.SSLOptions.Method := sslvSSLv3;
lSSLIOHandler.SSLOptions.Mode := sslmClient;
lSSLIOHandler.OnGetPassword := PasswordEvent;

lSOAPMsg := ...SOAP Msg...

msSource := TMemoryStream.Create();
msSource.Write(Pointer(lSOAPMsg)^, Length(lSOAPMsg));

ssResponse := TStringStream.Create('');

lHttp.Post(UrlPAC, msSource, ssResponse);
ssResponse.Position := 0;
lSOAPMsg := ssResponse.DataString;


Any ideas

TIA
#15994
Posted: 03/07/2011 11:39:36
by Eugene Mayevski (EldoS Corp.)

reset stream position to 0 before posting the stream.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 1817 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!