FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour load a file from Internet - RESOLVED
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
load a file from Internet - RESOLVED
Posted: Fri Jan 02, 2026 10:52 PM

I'm having trouble with a software program that uses URLDOWNLOADTOFILE.dll to download a file.
I also tried oHttp := CreateObject("WinHttp.WinHttpRequest.5.1"), but it still gives me an error.

old test

Function test() 
local cUrl:= "https://www.silvio.it/test.zip"
 local lreturn 
local cZipFile := "storico_"+DtoS(Date())+".zip" 
IF URLDOWNLOADTOFILE( 0,cUrl , cZipFile) =0 
lreturn := .t. 
else lreturn := .f. 
endif 
msginfo( lreturn) 
return nil 

DLL FUNCTION URLDOWNLOADTOFILE( pCaller AS LONG, cUrl AS LPSTR, cFileName AS LPSTR, nReserved AS DWORD, nFnCB AS LONG ) AS LONG; PASCAL FROM "URLDownloadToFileA" LIB "urlmon.dll"

test new not run

#include "fivewin.ch"

function Test()

   local oHttp := CreateObject("WinHttp.WinHttpRequest.5.1")
   local cUrl  := "https://www.silvio.it/test.zip"
   local cZip  := "storico_" + DtoS(Date()) + ".zip"

  

   oHttp:SetOption( 4, 13056 )   // ignora errori SSL

   oHttp:Open( "GET", cUrl, .F. )
   oHttp:Send()

   if oHttp:Status == 200
      MemoWrit( cZip, oHttp:ResponseBody )
      MsgInfo( "Scaricato correttamente ??" )
   else
      MsgStop( "Errore HTTP: " + LTrim(Str(oHttp:Status)) )
   endif

return nil

I rename the right url

I check if I can download the file and run good

the problem is not the tests but my Windows 10 computer is not updated so it has an expired certificate. How can I get around this error?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: load a file from Internet
Posted: Sat Jan 03, 2026 12:53 PM

It sounds like you are running into a classic TLS/SSL handshake failure. Since your Windows 10 is outdated, it likely lacks the modern "Root Certificates" (like Let's Encrypt or Sectigo) used by the server at silvio.it.

Even though you are using oHttp:SetOption(4, 13056) (which is meant to ignore unknown CAs and expired certs), WinHTTP still relies on the underlying Windows Schannel library, which can fail before the options are even processed if the protocol version is too old.

Here are the best ways to bypass or fix this:


---

1. Force TLS 1.2 via WinHTTP

Older versions of Windows 10/7 defaults to TLS 1.0 or 1.1. Most modern servers require TLS 1.2. You can force this by setting option 9.

Update your code to include this:

Code (harbour): Select all Collapse
local oHttp := CreateObject("WinHttp.WinHttpRequest.5.1")
local cUrl  := "https://www.silvio.it/test.zip"
local cZip  := "storico_" + DtoS(Date()) + ".zip"

// 1. Force TLS 1.2 (0x0800 = 2048)
oHttp:SetOption( 9, 2048 ) 

// 2. Ignore SSL errors (All flags: 13056)
oHttp:SetOption( 4, 13056 )

oHttp:Open( "GET", cUrl, .F. )
oHttp:Send()

2. The "PowerShell" Workaround

If WinHTTP continues to fail because the system's SSL library is too broken, you can call PowerShell directly from FiveWin. PowerShell uses a different engine and is often more successful at ignoring certificate validation.

Code (harbour): Select all Collapse
Function DownloadWithPS( cUrl, cFile )
   local cCommand := "powershell -Command " + ;
      "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; " + ;
      "(New-Object System.Net.WebClient).DownloadFile('" + cUrl + "', '" + cFile + "')"
   
   WaitRun( cCommand, 0 ) // 0 hides the console window
Return File( cFile )

3. Fixing the Root Certificate (Manual Fix)

Since the problem is an expired certificate on your Windows 10, the "correct" non-coding fix is to update the Root Certificates.

  1. Open Chrome or Edge and visit https://www.silvio.it.
  2. If the browser says "Your connection is not private," click the Lock icon -> Connection is secure -> Certificate is valid.
  3. Look at the "Certification Path" tab.
  4. Usually, downloading and installing the ISRG Root X1 certificate (for Let's Encrypt) fixes 90% of these issues on outdated Windows systems.

4. Why URLDownloadToFile is failing

The URLDownloadToFile function from urlmon.dll is even more restrictive than WinHTTP. It uses the same engine as Internet Explorer. If Internet Explorer cannot open the website, URLDownloadToFile will fail 100% of the time. I recommend sticking with the WinHttp.WinHttpRequest method as it is more flexible.


---
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: load a file from Internet
Posted: Sat Jan 03, 2026 08:38 PM

First sample

Error occurred at: 01/03/26, 21:32:29
Error description: (DOS Error -2147352570) WINOLE/1009 No exported method: SETOPTION
Args:
[ 1] = N 9
[ 2] = N 2048

Stack Calls

Called from: hbwin\oleauto.prg => TOLEAUTO:SETOPTION( 0 )
Called from: test.prg => TEST( 10 )

second sampe

not make errors but not download the zip file

I saw if I change the browser "in disguise" it not make ssl error and I can download manually the file

How I can from fwh to Navigate as in disguise ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: load a file from Internet - RESOLVED
Posted: Sat Jan 03, 2026 09:29 PM

Resolved with Mr. Gemini

#include "fivewin.ch"

Function test()
    local cUrl  := "myurl/storico.zip"
    local cFolder := "C:\work\errori\download\"
    local cZip  := cFolder + "storico.zip"
    local cCmd
    

if !lIsDir( cFolder ) ; MakeDir( cFolder ) ; endif

   
if File( cZip ) ; FErase( cZip ) ; endif

//  PowerShell complex for:
// 1.  to forceTLS 1.2
// 2. Ignore errori certificate (SSL Callback)
// 3. Simul User-Agent of a real  browser 

cCmd := "powershell -Command " + ;
        "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; " + ;
        "[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }; " + ;
        "$web = New-Object System.Net.WebClient; " + ;
        "$web.Headers.Add('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64)'); " + ;
        "$web.DownloadFile('" + cUrl + "', '" + cZip + "')"


WaitRun( cCmd, 0 )

if File( cZip )     //.and. DirectoryRec( cZip )[1][2] > 0
    MsgInfo( "Scaricato correttamente!" )
else
    MsgStop( "Il download è fallito. Possibile blocco del Firewall o indirizzo non raggiungibile." )
endif
return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion