Reputation: 726
I would like to get data from a website using Indy, but its not working. I get the following error:
Error connecting with SSL.
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Here is the code:
var
AMS: TMemoryStream;
begin
AMS := TMemoryStream.Create;
try
IdHTTP1.Get('https://www.optionsprofitcalculator.com/ajax/getStockPrice?stock=hca&reqId=0', AMS);
AMS.SaveToFile('c:\test.txt');
finally
FreeAndNil(AMS);
end;
end;
And the components:
object IdHTTP1: TIdHTTP
IOHandler = IdSSLIOHandlerSocketOpenSSL1
AllowCookies = True
HandleRedirects = True
ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0
Request.Connection = 'keep-alive'
Request.ContentLength = -1
Request.ContentRangeEnd = -1
Request.ContentRangeStart = -1
Request.ContentRangeInstanceLength = -1
Request.Accept =
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp' +
',*/*;q=0.8'
Request.AcceptEncoding = 'gzip, deflate, br'
Request.AcceptLanguage = 'hu-HU,hu;q=0.8,en-US;q=0.5,en;q=0.3'
Request.BasicAuthentication = False
Request.UserAgent =
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:77.0) Gecko/20100101' +
' Firefox/77.0'
Request.Ranges.Units = 'bytes'
Request.Ranges = <>
HTTPOptions = [hoForceEncodeParams]
Left = 110
Top = 155
end
object IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL
MaxLineAction = maException
Port = 0
DefaultPort = 0
SSLOptions.Method = sslvSSLv23
SSLOptions.SSLVersions = [sslvSSLv2, sslvSSLv3, sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]
SSLOptions.Mode = sslmUnassigned
SSLOptions.VerifyMode = []
SSLOptions.VerifyDepth = 0
Left = 155
Top = 155
end
I have no clue where the problem is. If it cannot be achieved with Indy, I would like to know if there is any standard Delphi component to communicate with HTTPS servers?
Upvotes: 1
Views: 872
Reputation: 726
Mystery solved.
The mentioned site using TLS 1.3 which not supported by the Indy, yet.
Thanks to Remy Lebeau, who helped me in this investigation.
Upvotes: 2
Reputation: 199
As suggested by Remy Lebeau;
I am using NetHttpClient. It uses the operating system's SSL. If you do not have to use Indy, you can use this component.
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
try
NetHTTPClient1.Get('https://www.optionsprofitcalculator.com/ajax/getStockPrice?stock=hca&reqId=0', Stream);
Stream.SaveToFile('c:\test.txt');
finally
FreeAndNil(Stream)
end;
You can try it this way. I tested it and it works.
Upvotes: 1