Question about wfReadUrl() - SOLVED

Question about wfReadUrl() - SOLVED

Postby driessen » Fri Apr 05, 2024 7:55 am

Hello,

I use this code to check if a website exists or not.
Code: Select all  Expand view
FUNCTION wfReadURL(cUrl)

   LOCAL cFile  := SUBSTR(cUrl,RAT("/",cUrl)+1)
   LOCAL cExist := .F.

   LOCAL oUrl,oCli

   cUrl := LOWER(cUrl)

   BEGIN SEQUENCE

         oUrl := TUrl():New(cUrl)
         IF EMPTY(oUrl) ; BREAK ; ENDIF
         oCli := TIPClientHttp():New(oUrl)       ***
         IF EMPTY(oCli) ; BREAK ; ENDIF
         IF !oCli:Open() ; BREAK ; ENDIF
         IF !oCli:ReadToFile(cFile) ; BREAK ; ENDIF
         IF PAR1->TESTNOTRY
            cExist := "OK" $ UPPER(oCli:cReply)
         ELSE
            TRY
               cExist := "OK" $ UPPER(oCli:cReply)
            CATCH
               cExist := .T.
            END
         ENDIF
         oCli:Close()
   END SEQUENCE

RETURN(cExist)

It works fine for "http://" urls, but if I use to check it for a "https://", I got this error:
Code: Select all  Expand view
Error BASE/1081  Operation not supported: TIPCLIENTHTTP:new()
It happens on the line where I put ***.

I need this function to work for https. Who can I do this?

Thanks.
Last edited by driessen on Sat Apr 06, 2024 8:17 am, edited 1 time in total.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about wfReadUrl()

Postby cmsoft » Fri Apr 05, 2024 3:25 pm

Puedes usar la funcion WebPageContents(cUrl)

Code: Select all  Expand view

if !Empty(WebPageContents(cUrl))
   //... tu codigo
else
   MsgStop('Url not found')
endif
 
User avatar
cmsoft
 
Posts: 1290
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Question about wfReadUrl()

Postby driessen » Fri Apr 05, 2024 3:30 pm

Thanks a lot for trying to help me.

I tested you suggestion.
Unfortunately, the function you suggested is only working for http, not for https.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about wfReadUrl()

Postby Enrico Maria Giordano » Fri Apr 05, 2024 5:28 pm

Michel, please show a little and complete PRG example of what you are trying to do and I will fix it.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Question about wfReadUrl()

Postby driessen » Fri Apr 05, 2024 8:30 pm

Enrico,

Thank you so much for trying to help me.

My website has 3 different url's, all showing the same website.

Because some antivirus software is blocking some of my url's, I want to check which url is working fine.
Usuaslly my url's are working ok with the prefix "https".
THe function wfReadUrl() which I use to check if the url is working, is working fine with the prefix "http", but results into an error "no exported method" with the prefix "https".

This is the code how I want to check my url's:
Code: Select all  Expand view
  DO CASE
      CASE !wfReadURL("http://www.ma-consult.be")  ; xDownWeb := "http://www.ma-consult.be"
      CASE !wfReadURL("https://www.ma-consult.be") ; xDownWeb := "https://www.ma-consult.be"
      CASE !wfReadURL("http://ma-consult.be")      ; xDownWeb := "http://ma-consult.be"
      CASE !wfReadURL("https://ma-consult.be")     ; xDownWeb := "https://ma-consult.be"
      CASE !wfReadURL("http://www.juda.be")        ; xDownWeb := "http://www.juda.be"
      CASE !wfReadURL("https://www.juda.be")       ; xDownWeb := "https://www.juda.be"
      CASE !wfReadURL("http://juda.be")            ; xDownWeb := "http://juda.be"
      CASE !wfReadURL("https://juda.be")           ; xDownWeb := "https://juda.be"
      CASE !wfReadURL("http://www.curato.be")      ; xDownWeb := "http://www.curato.be"
      CASE !wfReadURL("https://www.curato.be")     ; xDownWeb := "https://www.curato.be"
      CASE !wfReadURL("http://curato.be")          ; xDownWeb := "http://curato.be"
      CASE !wfReadURL("https://curato.be")         ; xDownWeb := "https://curato.be"
   ENDCASE
The result is put into the variable xDownWeb which I use later to perform a download.

The code of the wfReadUrl() can be found in this topic.

Is that enough information?

Thank you.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about wfReadUrl()

Postby cmsoft » Fri Apr 05, 2024 8:46 pm

Prueba este ejemplo, aqui funciona bien con https
Code: Select all  Expand view

#include "FiveWin.ch"
FUNCTION Main()
local aUrl := {'https://forums.fivetechsupport.com/download/file.php?avatar=86_1402579120.jpg',;
               'https://forums.fivetechsupport.com/download/file.php?avatar=294_1327638239.jpg',;
               'https://forums.fivetechsupport.com/download/file.php?avatar=xxxxxxxxxxxxxx.jpg',; //Not found
               'http://sistemas.mercedes.gob.ar/medidores/img/logo.png'}, i,  oDlg1, oBrw

FOR i := 1 to 4
    if Empty(WebPageContents(aUrl[i]))      
      aUrl[i] := '..\bitmaps\16exit.bmp'
    endif      
next i
DEFINE DIALOG oDlg1 TITLE "Imagenes Web" SIZE 300,300 PIXEL TRUEPIXEL RESIZABLE
   @ 60, 20 XBROWSE oBrw SIZE 200,250 pixel OF oDlg1 ARRAY aUrl  ;
      HEADERS "Imagen";
      COLUMNS 1;
      SIZES 70;
      CELL LINES NOBORDER
   WITH OBJECT oBrw
      :nRowHeight    := 70
      :aCols[1]:cDataType := "P"
      :CreateFromCode()
   END
ACTIVATE DIALOG oDlg1 CENTERED            
RETURN nil
 
User avatar
cmsoft
 
Posts: 1290
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Question about wfReadUrl()

Postby Enrico Maria Giordano » Fri Apr 05, 2024 9:13 pm

Try something like this:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    ? URLEXIST( "https://www.emagsoftware.it" )
    ? URLEXIST( "https://www.notexistent.it" )

    RETURN NIL


#command IF <condition> THEN <*statements*> => if <condition> ; <statements> ; end


STATIC FUNCTION URLEXIST( cUrl, oHtp )

    LOCAL lOk := .F.

    TRY
        DEFAULT oHtp := CREATEOBJECT( "MSXML2.SERVERXMLHTTP" )

        oHtp:Open( "GET", cUrl, .F. )

        oHtp:Send()

        IF oHtp:Status != 200 THEN BREAK

        lOk = .T.
    CATCH
    END

    RETURN lOk
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Question about wfReadUrl()

Postby driessen » Fri Apr 05, 2024 10:16 pm

Hello Ceasar and Enrico,

I tried both suggestions.

They both work, but both suggestions do have a problem in case the url doesn't exist or doesn't react.
It lasts at least 1 to 2 minutes before the test is passed.

Can we do something about it?

But thank you very much for your suggestions.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about wfReadUrl()

Postby Enrico Maria Giordano » Sat Apr 06, 2024 7:33 am

Here it is returning immediately. Can you post a sample showing that long timeout, please?
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Question about wfReadUrl()

Postby driessen » Sat Apr 06, 2024 8:05 am

Enrico,

Try this:
Code: Select all  Expand view
  DO CASE
     CASE UrlExist("https://www.maconsult.be") ; xDownWeb := "https://www.maconsult.be"
     CASE UrlExist("https://www.ma-consult.be") ; xDownWeb := "https://www.ma-consult.be"
  ENDCASE
The url http://www.maconsult.be doesn't exist. So it takes between 1 and 2 minutes before the next CASE is executed, resulting into xDownWeb = "https://www.ma-consult.be.

Another question. What if a url is blocked by a firewall or an antivirus. What will happen then?
That is de problem I have, especially wit BitDefender.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about wfReadUrl()

Postby driessen » Sat Apr 06, 2024 8:17 am

Enrico,

I just did a test on a system of one of my customers who is using BitDefender.
BitDefender blocks www.ma-consult.be, but does not block the other url's.

With your suggestion using UrlExist(), a blocked URL returns into a .F., the other URL's, return into a .T.

So in case www.ma-consult.be is blocked, the url www.juda.be is used.
And that is what I wanted to happen.

So, my problem is solved, thanks to you.

Thank you so much for your help.
Have a nice weekend.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about wfReadUrl() - SOLVED

Postby Enrico Maria Giordano » Sat Apr 06, 2024 8:18 am

Try this:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    ? URLEXIST( "https://www.emagsoftware.it" )
    ? URLEXIST( "https://www.maconsult.be" )

    RETURN NIL


#command IF <condition> THEN <*statements*> => if <condition> ; <statements> ; end


STATIC FUNCTION URLEXIST( cUrl, oHtp )

    LOCAL lOk := .F.

    TRY
        DEFAULT oHtp := CREATEOBJECT( "MSXML2.SERVERXMLHTTP" )

        oHtp:SetTimeouts( 1, 1, 1, 1 )

        oHtp:Open( "GET", cUrl, .F. )

        oHtp:Send()

        IF oHtp:Status != 200 THEN BREAK

        lOk = .T.
    CATCH
    END

    RETURN lOk
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Re: Question about wfReadUrl() - SOLVED

Postby nageswaragunupudi » Sat Apr 06, 2024 11:48 pm

Another alternative
Code: Select all  Expand view
function ValidURL( cUrl )

   local cIp

   WsaStartUp()
   cIp = GetHostByName( cUrl )
   WsaCleanUp()

return cIp != "0.0.0.0"


Does this work for you? If it is working is it fast in all cases?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Question about wfReadUrl() - SOLVED

Postby driessen » Sun Apr 07, 2024 4:58 am

Mr. Rao,

Thanks for your suggestion.
I will test it.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 79 guests