Page 1 of 1

How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 4:42 pm
by FWExplorer
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.

Re: How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 5:03 pm
by Antonio Linares
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)

Re: How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 5:09 pm
by Antonio Linares
Here you have a working example with credentials:

http://forums.fivetechsupport.com/viewt ... 92#p234092

Re: How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 5:20 pm
by FWExplorer
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)

Re: How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 7:37 pm
by FWExplorer
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: Select all

#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

//----------------------------------------------------------------------------//

 

Re: How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 7:44 pm
by Antonio Linares
D.

> Which library has olefuncs.prg already linked in?

FiveH.lib

Re: How to check the status of a url, with credentials

Posted: Tue Dec 29, 2020 7:54 pm
by FWExplorer
Never mind. I typed build.bat, rather than buildh.bat. Everything's good.