-3

I'm trying to post on a web service via TIdHTTP (Indy) using Delphi 5, and whenever i call the post method, it returns an "Error connecting with SSL error" exception.

This is the code i'm trying to run

FHandle                        := TIdSSLIOHandlerSocket.Create(nil);
FHandle.SSLOptions.Method      := sslvTLSv1;
IdHttp.IOHandler               := FHandle;
IdHttp.HandleRedirects         := True;

IdHTTP.Request.CustomHeaders.Add('Content-Type: application/json');
IdHttp.Request.ContentType := 'application/json';

Load();

vAux := TMemoryStream.Create();
try
  WriteStringToStream(vAux, edJson.Text);
  vAux.Position := 0;
  vRet := IdHTTP.Post(edHost.Text, vAux);
finally
  vAux.Free();
end;

It seems that no matter what i change in CustomHeaders or any other property, the same error happens.

I try changing de SSLOption.Method to all the available ones, but i can't get it to work.

Any suggestion for me to try?

Rodolfo Donã Hosp
  • 1,037
  • 1
  • 11
  • 23
  • Enhance verbosity? Does the same code works towards another server? Does another client works towards the same server as the one your application queries? – Patrick Mevzek Jun 28 '18 at 19:33
  • I didn't put any of those because i can't answer precisely. I tried on other servers the same code and it works, but i don't think that would be a reliable information since it's a completely different scenario. And yes, other clients can post on the same server, as i am trying to post on an API of a national company – Rodolfo Donã Hosp Jun 28 '18 at 19:37
  • 1
    So you need to get more details on the exception... Because there are a ton of possible TLS errors, starting with certificate/CA mismatches... If you gave the remote URL you try to access maybe other people could try to and give you insights. – Patrick Mevzek Jun 28 '18 at 19:43
  • 2
    Many websites nowadays have dropped support for TLS 1.0 and now require TLS 1.1+. You are using Indy 9, which doesn't support TLS 1.1+. You likely need to upgrade to Indy 10 to do what you want. On a side note, DO NOT use the `CustomHeaders` property to send a `Content-Type` header, only use the `Request.ContentType` property. You are sending 2 `Content-Type` headers to the server, which is likely to confuse it. – Remy Lebeau Jun 28 '18 at 19:55
  • Thank you for the side note, will keep that in mind. I just tried running the same code on a test application on Delphi XE7, and the error persists with all available versions. – Rodolfo Donã Hosp Jun 28 '18 at 20:33
  • @RodolfoDonãHosp are you using the Indy that shipped with XE7? It is pretty old itself. Have you tested using the latest version available from Indy's SVN? Can you provide the actual URL you are posting to, for testing? – Remy Lebeau Jun 29 '18 at 09:56
  • @RodolfoDonãHosp XE7 was released in 2014. Lots of updates and fixes to Indy since then. – Remy Lebeau Jun 29 '18 at 14:56
  • @RemyLebeau So you don't think theres a way to work around this error using Delphi 5? – Rodolfo Donã Hosp Jun 29 '18 at 20:11
  • @RodolfoDonãHosp can't say for sure until I can look at the actual SSL handshake, but I suspect no. – Remy Lebeau Jun 29 '18 at 23:09
  • Why are you not simply upgrading Indy as Remy suggested? He's one of the principle maintainers of Indy, so he knows what he's talking about most (if not all) of the time. Do you have a specific reason *not* to upgrade that you've not told us? You've also been asked to provide more specific information that we can use for testing, but have not edited to do so. – Ken White Jul 10 '18 at 12:32
  • Because with Indy 10 still didn't work for me. I'm running tests on a small application using XE7 and Indy 10, but the problem persists (also because the question was near dead). Guess i forgot to mention i re-run the test upgrading indy, sorry for letting that slide – Rodolfo Donã Hosp Jul 10 '18 at 12:38
  • I figured it out what the problem was. It was a certificate file that was faulty and i didn't even realized it was there. Thank you guys for the reply and sorry for the details i forgot to mention – Rodolfo Donã Hosp Jul 10 '18 at 13:54

1 Answers1

0

I figured it out what the problem was. It was a certificate file that was faulty on the CertFile property from TIdSSLIOHandlerSocket component and i didn't even realized it was there. After pointing out to the right certificate file everything worked out smoothly. Thank you guys for the insights!

Rodolfo Donã Hosp
  • 1,037
  • 1
  • 11
  • 23