FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour function urlLoad( cUrl )
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
function urlLoad( cUrl )
Posted: Fri Feb 16, 2024 07:10 PM
Thanks to Charly (Carles Aubia)
Code (fw): Select all Collapse
#include "hbcurl.ch"

function Main()

   ? urlLoad( "https://raw.githubusercontent.com/FiveTechSoft/harbourPackages/main/python/init.prg" )

return nil

function urlLoad( cUrl )

   local hCurl, nRet
   
   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_DOWNLOAD )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )       
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYHOST, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION ) 
      curl_easy_setopt( hCurl, HB_CURLOPT_FILETIME, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, SubStr( cUrl, RAt( "/", cUrl ) + 1 ) )
      curl_easy_setopt( hCurl, HB_CURLOPT_NOPROGRESS, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, .F. )     
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR , .T. )
        
      nRet = curl_easy_perform( hCurl )
      curl_easy_cleanup( hCurl ) 
   endif      
      
return nRet
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: function urlLoad( cUrl )
Posted: Fri Feb 16, 2024 08:23 PM
Dear Antonio,

Concept package, Click and go ! :wink:

Nice wekend.
C.
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 231
Joined: Fri Jul 20, 2012 01:49 AM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 12:56 AM
Good Job Charly, very useful 8)
Regards,

Lailton Fernando Mariano
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 08:55 AM
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   cUrl :=  "https://raw.githubusercontent.com/FiveTechSoft/harbourPackages/main/python/init.prg"
   ? WebPageContents( cUrl ) // --> "// dummy file"

return nil
Is this not correct?
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 09:21 AM
Or this?
Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    ? URLDOWNLOADTOFILE( "https://www.emagsoftware.it/logo.png", "emaglogo.png" ) = 0

    RETURN NIL


#pragma BEGINDUMP

#include "hbapi.h"
#include "urlmon.h"
#include "wininet.h"


HB_FUNC( URLDOWNLOADTOFILE )
{
    DeleteUrlCacheEntry( hb_parc( 1 ) );

    hb_retnl( URLDownloadToFile( NULL, hb_parc( 1 ), hb_parc( 2 ), 0, NULL ) );
}

#pragma ENDDUMP
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 11:18 AM
Hello friends,

After it appears that cURL is becoming increasingly important and widespread, I am posting some information on the cURL Lib here, which I created with the help of ChatGPT.

https://mybergland.com/fwforum/curl-lib.pdf

Interestingly, I just used this function yesterday as well, but from PHP, to call mod harbour.

https://forums.fivetechsupport.com/viewtopic.php?f=45&t=44242

Best regards,
Otto
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 11:24 AM

I don't like it. It requires a 4 MB DLL! Or am I wrong?

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 12:01 PM
With Image URL
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 12:07 PM
There are many ways to skin the cat. :-)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 01:19 PM

Both the functions WebPageContents() and URLDownloadToFile() work only on Windows OS.

For Web Applications, we need platform independent tools and CURL seems to be the popular choice.

Regards



G. N. Rao.

Hyderabad, India
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 01:21 PM
Enrico Maria Giordano wrote:Or this?
Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    ? URLDOWNLOADTOFILE( "https://www.emagsoftware.it/logo.png", "emaglogo.png" ) = 0

    RETURN NIL


#pragma BEGINDUMP

#include "hbapi.h"
#include "urlmon.h"
#include "wininet.h"


HB_FUNC( URLDOWNLOADTOFILE )
{
    DeleteUrlCacheEntry( hb_parc( 1 ) );

    hb_retnl( URLDownloadToFile( NULL, hb_parc( 1 ), hb_parc( 2 ), 0, NULL ) );
}

#pragma ENDDUMP
Dear Enrico, que me falta?

Code (fw): Select all Collapse
URLLOAD2.c:

Turbo Incremental Link 6.97 Copyright (c) 1997-2022 Embarcadero Technologies, Inc.
Error: Unresolved external 'DeleteUrlCacheEntry' referenced from C:\FWH1905\SAMPLES\URLLOAD2.OBJ
Error: Unresolved external 'URLDownloadToFileA' referenced from C:\FWH1905\SAMPLES\URLLOAD2.OBJ
Error: Unable to perform link
* Linking errors *
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 02:06 PM

You have to link wininet.lib from your C compiler.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 02:09 PM
nageswaragunupudi wrote:Both the functions WebPageContents() and URLDownloadToFile() work only on Windows OS.
For Web Applications, we need platform independent tools and CURL seems to be the popular choice.
I never needed of such a function for web applications.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 02:55 PM
Enrico, here how I use it with web:


https://forums.fivetechsupport.com/viewtopic.php?f=45&t=44242

Best regards,
Otto
Posts: 179
Joined: Fri Dec 07, 2007 01:26 PM
Re: function urlLoad( cUrl )
Posted: Sat Feb 17, 2024 04:45 PM

Dear friends,

please can you help me...I try to follow along and was busy reading what I found in our manual folder (fwfun.chm, fwcmd.chm, fwclass.chm,...).

Now I am curios about XImage(), WebpageContents() where could I find out more about these interesting things? Maybe someone would be kind enough to point me to a wiki for these?

Kind regards to all of you and a thank you - also to those who wrote the wonderful documentations ... they are of immense value - as the forum is.