FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to check the status of a url, with credentials
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 04:42 PM

Hi,

I wrote a python utility earlier in the year that checks connectivity, and optionally html file size, and optionally with credentials.

Are there some FW snippets that will accomplish the same thing? I already tried searching through Minigui and played with TIpClientHttp, and cannot find anything in the fwh distribution.

Some of the sites I'm checking are https ; some are http.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 05:03 PM

This works without credentials:

function WebPageContents( cUrl, lText ) --> cContents

For credentials we have to use:

user = "someusername"
password = "somepassword"
xmlhttp.setRequestHeader "Authorization", "Basic " + Base64Encode(user + ":" + password)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 05:09 PM

Here you have a working example with credentials:

viewtopic.php?p=234092#p234092

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
Re: How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 05:20 PM
Thanks, Antonio.

Antonio Linares wrote:This works without credentials:

function WebPageContents( cUrl, lText ) --> cContents

For credentials we have to use:

user = "someusername"
password = "somepassword"
xmlhttp.setRequestHeader "Authorization", "Basic " + Base64Encode(user + ":" + password)
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
Re: How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 07:37 PM
What option do we need, on the Buildh command line to include the FW Ole functions?

I put PingValidate.prg, containing WebPageContents() in the samples folder. But we have some missing externals.

Which library has olefuncs.prg already linked in?


Error: Unresolved external '_HB_FUN_FWGETOLEOBJECT' referenced from C:\FWH\SAMPLES\PINGVALIDATE.OBJ
Error: Unresolved external '_HB_FUN_FW_GT' referenced from C:\FWH\SAMPLES\PINGVALIDATE.OBJ
Error: Unable to perform link
* Linking errors *



Code (fw): Select all Collapse
#include "fivewin.ch"

function WebPageContents( cUrl, lText )

   local oHttp, cContents := ""
   local nOle  := 0
   local aOle  := { "MSXML2.XMLHTTP", "WINHTTP.WinHttpRequest.5.1" }

   if Lower( Left( cUrl, 7 ) ) == "http://" .or. Lower( Left( cUrl, 8 ) ) == "https://"

      do while Empty( cContents ) .and. nOle < 2
         nOle++
         TRY
            oHttp     := FWGetOleObject( aOle[ nOle ] )
            oHttp:Open("GET", cUrl, .f. )
            oHttp:Send()
            DEFAULT lText := .f.
            if lText
               cContents   := oHttp:ResponseText()
            else
               cContents   := oHttp:ResponseBody()
            endif
         CATCH
         END
      enddo
   endif

return cContents

//----------------------------------------------------------------------------//
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 07:44 PM

D.

> Which library has olefuncs.prg already linked in?

FiveH.lib

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
Re: How to check the status of a url, with credentials
Posted: Tue Dec 29, 2020 07:54 PM

Never mind. I typed build.bat, rather than buildh.bat. Everything's good.

Continue the discussion