EldoS | Feel safer!

Software components for data protection, secure storage and transfer

External exception with TElHTTPSClient

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#37144
Posted: 07/01/2016 18:11:00
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

I am getting this error when trying to upload a file using TElHTTPSClient.
External exception C0000008 when doing a postwebform
I am using Delphi XE2, SBB 14 on Win2008R2 server

Here is my code


procedure Tfrmmain.Button2Click(Sender: TObject);
var
vstream: TFileStream;
vlist: TStringList;
vcontent,vurl,vfilename:string;
i:integer;
begin
vfilename:='N:\test.txt';
try
vurl :='XXX';
if FileExists(vfilename) then
begin
vstream := TFileStream.Create(vfilename, fmOpenRead + fmShareDenyWrite);
vlist := TStringList.Create;
vcontent := 'text/plain';
ElHTTPSClient1.SSLEnabled:=true;
ElHTTPSClient1.SocksUserCode:='XXX';
ElHTTPSClient1.SocksPassword:='XXX';

ElHTTPSClient1.PostWebForm(vurl,vlist,'userfile', ExtractFileName(vfilename), vstream, vcontent, True);
freeandnil(vlist);
freeandnil(vstream);
ElHTTPSClient1.Close(true);
end;
except
on e:exception do
raise;
end;
end;
#37145
Posted: 07/01/2016 19:49:02
by Eugene Mayevski (EldoS Corp.)

CloseStream parameter must be false OR you dont need to delete vstream - by doing this you are deleting the object twice.

On a side note it would help a lot if you used CODE button located above the text entry box (alternatively you can write [ CODE ] and [ /CODE ] tags by hand) to mark the beginning and the end of the code blocks in your messages. This would enable syntax highlighting and line numbering on the code and make it easier for analysis.


Sincerely yours
Eugene Mayevski
#37161
Posted: 07/05/2016 14:01:04
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Tku

That fixed that error message.
However I am now getting the following error:

Wrong socket state 0 in CanReceive (error code is 96258)

This occurs right after the first SendData event

Code
procedure Tfrmmain.Button2Click(Sender: TObject);
var
  vstream: TFileStream;
  vlist: TStringList;
  vcontent,vurl,vfilename:string;
  i:integer;
begin
  vfilename:='N:\test.zip';
  try
    vurl := 'XXX';
    showstatus('URL: ' + vurl + ' Filename: ' + vfilename);
    if FileExists(vfilename) then
    begin
      vstream := TFileStream.Create(vfilename, fmOpenRead + fmShareDenyWrite);
      vlist := TStringList.Create;
      vcontent := 'application/zip';
      ElHTTPSClient1.SSLEnabled:=true;
      ElHTTPSClient1.SocksUserCode:='XXX';
      ElHTTPSClient1.SocksPassword:='XXX';
      ElHTTPSClient1.PostWebForm(vurl, vlist, 'userfile', ExtractFileName(vfilename), vstream, vcontent, True);
      freeandnil(vlist);
    end
    else
      showstatus('Cant open ' + vfilename);
  except
    on e:exception do
    showstatus('ERROR in HTTPUpload: ' + e.Message);
  end;
end;
#37164
Posted: 07/06/2016 08:53:03
by Eugene Mayevski (EldoS Corp.)

You setup SOCKS username and password, but don't configure SOCKS (don't enable it and don't set the address). Is this correct?

If you have omitted some settings, they can be important for diagnosis of the problem.


Sincerely yours
Eugene Mayevski
#37165
Posted: 07/06/2016 13:08:52
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Yes. That was because the site requires a username and password.
In looking at the properties further I discovered that RequestParameters also has a UserName and password.
I tested using that rather than SOCKS but still get the same error.

I am using the default settings for TElHTTPSClient
Except for the SocksAuthentication value
Code
  object ElHTTPSClient1: TElHTTPSClient
    SocketTimeout = 60000
    Versions = [sbTLS12]
    SSLOptions = [ssloAutoAddServerNameExtension]
    LocalPort = 0
    IncomingSpeedLimit = 0
    OutgoingSpeedLimit = 0
    UseSSLSessionResumption = False
    ForceResumeIfDestinationChanges = False
    SocksAuthentication = saUsercode
    WebTunnelPort = 3128
    SocketBinding.Port = 0
    SocketBinding.ReuseAddress = False
    SocketBinding.PortRangeFrom = 0
    SocketBinding.PortRangeTo = 0
    RenegotiationAttackPreventionMode = rapmAuto
    SSLEnabled = False
    RequestParameters.ContentLength = -1
    RequestParameters.ContentRangeStart = -1
    RequestParameters.ContentRangeEnd = -1
    RequestParameters.ContentRangeFullSize = -1
    RequestParameters.UserAgent = 'SecureBlackbox'
    RequestCompressionLevel = 0
    RequestCompressionGZip = False
    KeepAlivePolicy = kapStandardDefined
    HTTPVersion = hvHTTP10
    UseNTLMAuth = False
    UseDigestAuth = False
    PersistentAuthHeader = True
    ForceNTLMAuth = False
    Use100Continue = False
    HTTPProxyPort = 3128
    HTTPProxyAuthentication = wtaNoAuthentication
    UseHTTPProxy = False
    IgnoreUnknownTransferEncodings = False
    OnWebSocketConnectionEstablished = ElHTTPSClient1WebSocketConnectionEstablished
    OnData = ElHTTPSClient1Data
    OnDocumentBegin = ElHTTPSClient1DocumentBegin
    OnDocumentEnd = ElHTTPSClient1DocumentEnd
    OnSendData = ElHTTPSClient1SendData
    OnCertificateValidate = ElHTTPSClient1CertificateValidate
    OnCloseConnection = ElHTTPSClient1CloseConnection
    OnError = ElHTTPSClient1Error
    Left = 352
    Top = 128
  end
#37186
Posted: 07/07/2016 09:28:57
by Eugene Mayevski (EldoS Corp.)

Quote
GERALD MORRIS wrote:
Yes. That was because the site requires a username and password. In looking at the properties further I discovered that RequestParameters also has a UserName and password.


Right, these are the correct properties to use for authentication. Yet it can happen, that you need some other kind of authentication (like Digest or NTLM authentication).

To understand the problem better I'd like to ask you a couple of questions. Please do provide the answers to all the questions.

1) Do you happen to get your ElHTTPSClient1Error and/or ElHTTPSClient1CloseConnection methods called? In other words, is anything reported before the connection is closed?

2) please put a breakpoint in ElHTTPSClient1CertificateValidate and check whether validation procedures return true in Validate parameter. Please let me know the outcome. (!) If they don't return true, then connection won't be established. Validation should be done properly and in full, however for debugging purposes you can omit all validations and just put "Validate = true" . Remember to remove it later, when your problem is solved.


Sincerely yours
Eugene Mayevski
#37193
Posted: 07/07/2016 10:52:32
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Tku Eugene
I am logging all those events
The CertificateValidate code is validate:=true

Here is the log
7/7/16 07:48:57 AM: CertificateValidate
7/7/16 07:48:58 AM: SendData
7/7/16 07:49:06 AM: ERROR in HTTPUpload: Wrong socket state 0 in CanReceive (error code is 96258)

The Error and CloseConnection events never get called

Gerald
#37194
Posted: 07/07/2016 11:06:54
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Clarification
The "ERROR in HTTPUpload" message in my log is from the try except clause.
The ElHTTPSClient1Error never gets triggered
#37216
Posted: 07/08/2016 11:32:49
by Vsevolod Ievgiienko (EldoS Corp.)

Does the same problem occur if you change this

Code
Versions = [sbTLS12]


to

Code
Versions = [sbTLS1, sbTLS11, sbTLS12]
?
#37219
Posted: 07/08/2016 13:21:42
by GERALD MORRIS (Standard support level)
Joined: 11/08/2010
Posts: 27

Yes


Code
Versions = [sbTLS1, sbTLS11, sbTLS12]
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

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