Search code examples
delphic++builderindy10

What "Socket Error # 2" means in Indy components?


I have created an application that calls a web service using POST method in C++/Delphi. It works fine in the localhost under http, but when I try the https protocol in the production server, I get "Socket Error # 2". I have no idea what it means. The web server is providing https services to other applications (not Rad Studio) without problems. The code I use is extracted from a web site:

std::auto_ptr<TIdHTTP> httpPtr( new TIdHTTP(NULL) );
TIdHTTP *Http = httpPtr.get();
try
{
  TIdSSLIOHandlerSocketOpenSSL *SSL = new TIdSSLIOHandlerSocketOpenSSL( Http );
  // configure SSL settings as needed...
  Http->IOHandler = SSL;

  Http->HandleRedirects = true;
  Http->AllowCookies = false;
  Http->ConnectTimeout = 10000;
  Http->ReadTimeout = 10000;

  Http->Request->BasicAuthentication = true;
  Http->Request->Password = username;
  Http->Request->Username = password;

  Memo1->Text = Http->Post( "http://logs.domain.dk", json);
}
catch( const Exception &e )
{
  Memo1->Lines->Add(e.ClassName());
  Memo1->Lines->Add(e.Message);
  return;
}

UPDATE:

I have added the following code to see the messages from Fiddler.

IdHTTP1->ProxyParams->ProxyServer = "127.0.0.1"; 
IdHTTP1->ProxyParams->ProxyPort = 8888;

Now it works fine (with the Proxy for Fiddler), but of course, it is not the solution because the user will not have Fiddler. I do not know if it is important, but the https server does not use the normal https port. It uses 4001, but I pass this value in the url:

IdHTTP1->Post("https://myweb.com:4001/api/certificate", json);

What is happening? I am confused.


Solution

  • It seems that the problem happens with Indy + SSL + Windows 8.1

    The solution is simply to add:

    IdHTTP1->ReadTimeout = 30000;
    

    Problem solved!