Win 10 and getUrl

Win 10 and getUrl

Postby Silvio.Falconi » Thu Jun 09, 2022 7:37 am

TOday I have an error on Win 10 when I try to download a file from a website
Code: Select all  Expand view



#command DEFAULT <var> := <xpr> => if <var> = NIL ; <var> := <xpr> ; end
#command IF <condition> THEN <*statements*> => if <condition> ; <statements> ; end

Function Scarica_Storico(cUrl,cZipFile)
     local nVersionWin:=cWinVersion()
   If val(cWinVersion())=7
      Download_Windows_Seven(cUrl,cZipFile)
      else
         GETURLTOFILE(cUrl,cZipFile)
   Endif
return nil

STATIC FUNCTION GETURLTOFILE( cUrl, cFile, cUsr, cPsw )
    LOCAL lOk := .F.

    LOCAL oHtp, oStr, ex

    DEFAULT cFile := CFILENAME( STRTRAN( cUrl, "/", "\" ) )

    //TRY
        oHtp = CREATEOBJECT( "
Msxml2.XMLHTTP.6.0" )
        oHtp:Open( "
POST", cUrl, .F., cUsr, cPsw )
        oHtp:Send()

        IF oHtp:Status != 200 THEN BREAK
        MemoWrit(cFile,oHtp:ResponseBody)
        //oStr = CREATEOBJECT( "
ADODB.Stream" )
        //oStr:Open()
        //oStr:Type = 1
        //oStr:Write( oHtp:ResponseBody )
        //oStr:SaveToFile( cFile, 2 )
        //oStr:Close()

        lOk = .T.
    //CATCH ex
    //        ? ex:message
    //END

    RETURN lOk



Code: Select all  Expand view
 Error description: (DOS Error -2147352567) WINOLE/1007  Errore di sistema: -2147012890.
 (0x80072EE6): msxml6.dll
   Args:
     [   1] = C   POST
     [   2] = C   .\data\
     [   3] = L   .F.
     [   4] = U  
     [   5] = U  

Stack Calls
===========
   Called from:  => TOLEAUTO:OPEN( 0 )
   Called from: source\Aggiorna.prg => GETURLTOFILE( 94 )





I tried also with

Function Scarica_Storico(cUrl,cZipFile,oSay)
local nVersionWin:=cWinVersion()
local cFile,cREto

If val(cWinVersion())=7
Download_Windows_Seven(cUrl,cZipFile)
else
cRet := WebPageContents( cUrl )
MEMOWRIT( cZipFile,cRet)

Endif
return nil

but not happen nothing
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Win 10 and getUrl

Postby Jimmy » Sun Jun 12, 2022 8:07 am

hi Silvio,

try this
Code: Select all  Expand view
FUNCTION DownloadFromWWW( cUrl, cFile )

LOCAL oErr
LOCAL oHttp := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )

   IF FILE( cFile )
      hb_FileDelete( cFile )
   ENDIF

   IF .NOT. "http" $ cUrl
      RETURN .F.
   ENDIF

   BEGIN SEQUENCE WITH { | oErr | BREAK( oErr ) }
      oHttp:Open( "GET", cUrl, .F. )
      oHttp:setRequestHeader( "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" )
      oHttp:Send()

      IF oHttp:Status = 200
         StrFile( oHttp:ResponseBody(), cFile )
      ENDIF
      oHttp:Abort()

   RECOVER USING oErr
      MsgStop( "Error download " + cUrl )
   END SEQUENCE

RETURN FILE( cFile )
 

p.s. i don´t know what
Code: Select all  Expand view
setRequestHeader
mean.
i have FireFox installed and it work for me to download Logo of IPTV Station
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Win 10 and getUrl

Postby Silvio.Falconi » Sun Jun 12, 2022 7:59 pm

now I'm using

IF URLDOWNLOADTOFILE( 0,cUrl , cZipFile) =0
lreturn := .t.
else
lreturn := .f.
endif


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"


but sometimes run on win 10
on windows seven Have problem
I wish a system to use on every Operative system
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Win 10 and getUrl

Postby Otto » Mon Jun 13, 2022 8:35 pm

Silvio,
in one of my programs I see that I use now:

// static cHttpClass := "Microsoft.XmlHttp"
// static cHttpClass := "MSXML2.ServerXMLHTTP.6.0"
static cHttpClass := "WinHTTP.WinHTTPRequest.5.1"


Best regard,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Win 10 and getUrl

Postby Silvio.Falconi » Wed Jun 15, 2022 8:13 am

friends that protocols are not used on Windows and future

FUNCTION DownloadFromWWW( cUrl, cFile ) seems run ok on win10 on winseven I not tried
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests