EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElHTTPSClient Help

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
Posted: 03/07/2011 11:30:12
by Luis Arenal (Standard support level)
Joined: 05/10/2006
Posts: 9


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.

  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;
  lSOAPMsg := slAux.Text;

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

  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

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



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