How to check the status of a url, with credentials

How to check the status of a url, with credentials

Postby FWExplorer » Tue Dec 29, 2020 4: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.
FWExplorer
 
Posts: 100
Joined: Fri Aug 09, 2013 12:43 am

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

Postby Antonio Linares » Tue Dec 29, 2020 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Tue Dec 29, 2020 5:09 pm

Here you have a working example with credentials:

viewtopic.php?p=234092#p234092
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby FWExplorer » Tue Dec 29, 2020 5: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)
FWExplorer
 
Posts: 100
Joined: Fri Aug 09, 2013 12:43 am

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

Postby FWExplorer » Tue Dec 29, 2020 7: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: Select all  Expand view
#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

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

 
FWExplorer
 
Posts: 100
Joined: Fri Aug 09, 2013 12:43 am

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

Postby Antonio Linares » Tue Dec 29, 2020 7:44 pm

D.

> Which library has olefuncs.prg already linked in?

FiveH.lib
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby FWExplorer » Tue Dec 29, 2020 7:54 pm

Never mind. I typed build.bat, rather than buildh.bat. Everything's good.
FWExplorer
 
Posts: 100
Joined: Fri Aug 09, 2013 12:43 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests