Search code examples
delphi-2010winhttp

WinHTTP - The connection with the server was terminated abnormally


I import WinHTTP and try execute a request in a https url, like this:

function TForm1.GetPage(AURL: String): String; 
var 
  WinHttpRequest: IWinHTTPRequest; 
begin 
  CoInitialize(nil); 
  try 
    WinHttpRequest := CoWinHttpRequest.Create; 
    WinHttpRequest.Open('GET', AURL, False); 
    WinHttpRequest.Send(EmptyParam); 
    Result := WinHttpRequest.ResponseText; 
  finally 
    WinHTTPRequest := nil; 
    CoUninitialize; 
  end; 
end;

It works in same pages (ex: https://www.google.com), but not in others (ex: https://sourceforge.net), with error "The connection with the server was terminated abnormally".

Are there any additional settings I'm forgetting?

I'm using Delphi 2010.


Solution

  • Most servers have migrated away from accepting SSL incoming traffic in favor of TLS protocol. Windows 7 and 8 do not have TLS protocol defined and hence VBA sendss traffic with SSL which is then blocked/dropped by such servers.

    You will need to apply a 2-step patch/update to fix this for windows 7,

    Step 1. Get Microsoft Update: Download relevant (32-bits or 64-bits of user's Windows version) Microsoft Security Protocol Update and install if not already install.

    Step 2. Download Microsoft Easy Fix: Download Microsoft “Easy Fix” from Microsoft Support Article, and execute to set TLS 1.1+ as default.

    Source : Update to enable TLS 1.1 and TLS 1.2 as default secure protocols in WinHTTP in Windows