Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Is there a way to check if a URL exists without calling it?


  • Please log in to reply
15 replies to this topic

#1 LovinItAll

LovinItAll

    Seeker

  • Active Members
  • 36 posts

Posted 28 February 2006 - 05:21 PM

For instance, if I wanted to know if www.AnySite.com/AnyFile.html exists, is there a way to do this? Sort of like:

If www.AnySite.com/AnyFile.html exists then

else

endif

Edited by LovinItAll, 28 February 2006 - 05:25 PM.








#2 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,981 posts

Posted 28 February 2006 - 05:56 PM

For instance, if I wanted to know if www.AnySite.com/AnyFile.html exists, is there a way to do this? Sort of like:

If www.AnySite.com/AnyFile.html exists then

else

endif

Sure -- this should work...
Plain Text         
;Check existance of a URL ;adapted to AutoIt from <a href='http://www.developerfusion.co.uk/show/1605/' class='bbc_url' title='External link' rel='nofollow external'>http://www.developerfusion.co.uk/show/1605/</a> ;by DaleHohm ;Timeout values in milliseconds $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") If $oHttpRequest = 0 Then     ConsoleWrite("Error creating Object $oHttpRequest.  " & _                         "You must have 3.0 or later of the MSXML library to use this code" & @CR) EndIf $sTestUrl = "<a href='http://www.microsoft.com/nonexistingpage.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.microsoft.com/nonexistingpage.html"</a> With $oHttpRequest    .SetTimeouts ($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout)    .Open ("GET", $sTestUrl)    .Send    Select       Case .Status = 200;No problem!         ConsoleWrite($sTestUrl & " is a valid, available URL" & @CR)       Case .Status = 404;Not found         ConsoleWrite($sTestUrl & " could not be found (404 Error)" & @CR)       Case Else;Some other problem         ConsoleWrite("An unexpected HTTP Status value was returned: " & .Status & @CR)    EndSelect EndWith $oHttpRequest = ""


Enjoy,

Dale

Edit: Added check object creation and caveat about MSXML 3.0

Edited by DaleHohm, 28 February 2006 - 06:25 PM.

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

 

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

 

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y
Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble


#3 herewasplato

herewasplato

    Most Senile Poster

  • Active Members
  • PipPipPipPipPipPip
  • 4,426 posts

Posted 28 February 2006 - 06:14 PM

@DaleHohm,
I get:

>Running: (3.1.1.110):C:\Program Files\AutoIt3\beta\autoit3.exe "c:\Temp\SciTE-temp.au3"
C:\Temp\SciTE-temp.au3 (13) : ==> The requested action with this object has failed.:
.Send
.Send^ ERROR
>AutoIT3.exe ended.

with that code...
..

#4 Jos

Jos

    Je maintiendrai

  • Developers
  • 23,363 posts

Posted 28 February 2006 - 06:23 PM

Works fine for me...
Try this version to see what the problem with the Com object is..

Plain Text         
;Check existance of a URL ;adapted to AutoIt from <a href='http://www.developerfusion.co.uk/show/1605/' class='bbc_url' title='External link' rel='nofollow external'>http://www.developerfusion.co.uk/show/1605/</a> ;by DaleHohm ;Timeout values in milliseconds $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 ; Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") $sTestUrl = "<a href='http://www.microsoft.com/nonexistingpage.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.microsoft.com/nonexistingpage.html"</a> ; With $oHttpRequest    .SetTimeouts ($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout)    .Open ("GET", $sTestUrl)    .Send    Select       Case .Status = 200;No problem!         ConsoleWrite($sTestUrl & " is a valid, available URL" & @CR)       Case .Status = 404;Not found         ConsoleWrite($sTestUrl & " could not be found (404 Error)" & @CR)       Case Else;Some other problem         ConsoleWrite("An unexpected HTTP Status value was returned: " & .Status & @CR)    EndSelect EndWith ; $oHttpRequest = "" ; ; Com Error Handler Func MyErrFunc()     $HexNumber = Hex($oMyError.number, 8)     $oMyRet[0] = $HexNumber     $oMyRet[1] = StringStripWS($oMyError.description,3)     ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)     SetError(1); something to check for when this function returns     Return EndFunc  ;==>MyErrFunc

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#5 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,981 posts

Posted 28 February 2006 - 06:30 PM

@DaleHohm,
I get:with that code...

Sorry, there is a requirement for MSXML 3.0. JdeB's error handler is always a good idea (when you aren't being lazy like I was :o ). I've also added a check to my original code that checks the status of the ObjCreate code.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

 

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

 

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y
Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble


#6 herewasplato

herewasplato

    Most Senile Poster

  • Active Members
  • PipPipPipPipPipPip
  • 4,426 posts

Posted 28 February 2006 - 06:31 PM

JdeB,

>Running: (3.1.1.110):C:\Program Files\AutoIt3\beta\autoit3.exe "c:\Temp\SciTE-temp.au3"
C:\Temp\SciTE-temp.au3 (34) : ==> Variable used without being declared.:
$oMyRet[0]= $HexNumber
^ ERROR
>AutoIT3.exe ended.


..

#7 LovinItAll

LovinItAll

    Seeker

  • Active Members
  • 36 posts

Posted 28 February 2006 - 06:36 PM

Dale - Thank you so much! You have come through for me in a clutch way -- again!

Regards ~ Lee

#8 herewasplato

herewasplato

    Most Senile Poster

  • Active Members
  • PipPipPipPipPipPip
  • 4,426 posts

Posted 28 February 2006 - 06:46 PM

Edit: Added check object creation and caveat about MSXML 3.0

If $oHttpRequest = 0 Then     ConsoleWrite("Error creating Object $oHttpRequest.  " & _                         "You must have 3.0 or later of the MSXML library to use this code" & @CR) EndIf
I never see that caveat in the console output:

>"C:\Program Files\AutoIt3\SciTe\CompileAU3\CompileAU3.exe" /run /beta /ErrorStdOut /in "c:\Temp\SciTE-temp.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams
>Running: (3.1.1.110):C:\Program Files\AutoIt3\beta\autoit3.exe "c:\Temp\SciTE-temp.au3"
C:\Temp\SciTE-temp.au3 (21) : ==> The requested action with this object has failed.:
.Send
.Send^ ERROR
>AutoIT3.exe ended.
>Exit code: 0 Time: 1.541

Edit: So I guess that I have MSXML 3.0 installed and I still get the error above.

http://www.microsoft.com/downloads/details...&displaylang=en

Edited by herewasplato, 28 February 2006 - 11:31 PM.

..

#9 Jos

Jos

    Je maintiendrai

  • Developers
  • 23,363 posts

Posted 28 February 2006 - 06:47 PM

JdeB,

I am sorry, copied it from another script and forgot about the array..

try this version of the ComErrorHandler Func
; Com Error Handler Func MyErrFunc()     $HexNumber = Hex($oMyError.number, 8)     ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & StringStripWS($oMyError.description,3) & @LF)     SetError(1); something to check for when this function returns     Return EndFunc  ;==>MyErrFunc

Edited by JdeB, 28 February 2006 - 06:47 PM.

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#10 herewasplato

herewasplato

    Most Senile Poster

  • Active Members
  • PipPipPipPipPipPip
  • 4,426 posts

Posted 28 February 2006 - 06:52 PM

I am sorry, copied it from another script and forgot about the array..

No problem. This is the output now:

>Running: (3.1.1.110):C:\Program Files\AutoIt3\beta\autoit3.exe "c:\Temp\SciTE-temp.au3"
### COM Error ! Number: 80020009 ScriptLine: 18 Description:The server name or address could not be resolved
### COM Error ! Number: 80020009 ScriptLine: 22 Description:The data necessary to complete this operation is not yet available.
An unexpected HTTP Status value was returned:
### COM Error ! Number: 80020009 ScriptLine: 25 Description:The data necessary to complete this operation is not yet available.
### COM Error ! Number: 80020009 ScriptLine: 25 Description:The data necessary to complete this operation is not yet available.
>AutoIT3.exe ended.


Edit: Tested without a proxy server to the net - works fine.
Returns (404 Error) as expected.

Edited by herewasplato, 28 February 2006 - 11:32 PM.

..

#11 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,214 posts

Posted 28 February 2006 - 07:22 PM

????

Ping ( address or hostname [, timeout] )

When the function fails (returns 0) @error contains extended information:
1 = Host is offline
2 = Host is unreachable
3 = Bad destination
4 = Other errors


????

8)

Posted Image

Clic The Pic!!!


#12 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,981 posts

Posted 02 March 2006 - 06:10 PM

No problem. This is the output now:

Edit: Tested without a proxy server to the net - works fine.
Returns (404 Error) as expected.

Here is a very good page about ServerXMLHTTP: Frequently asked questions about ServerXMLHTTP. One of the things it hilights is that ServerXMLHTTP does not do automatic proxy discovery and that you may have to run proxycfg.exe first... this would explain your trouble I believe.

There is an older component called XMLHTTP that is also discussed in that article that does do automatic proxy detection. I believe it could also be used to do this discovery, but from my experience may need some additional error handling when used in AutoIt. I have not done any testing of this however.

Dale

Edit: fixed hyperlink

Edited by DaleHohm, 02 March 2006 - 06:11 PM.

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

 

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

 

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y
Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble


#13 LovinItAll

LovinItAll

    Seeker

  • Active Members
  • 36 posts

Posted 03 March 2006 - 11:51 AM

????

Ping ( address or hostname [, timeout] )

When the function fails (returns 0) @error contains extended information:
1 = Host is offline
2 = Host is unreachable
3 = Bad destination
4 = Other errors
????

8)

I tried this originally, but Ping will not detect the existence of folders within a URL. For example:

ping("autoitscript.com") - will return the ping time

ping("autoitscript.com/AnyFolder") will always return 0, whether AnyFolder exists or not.

#14 nitekram

nitekram

    Ng1-Nf3

  • Active Members
  • PipPipPipPipPipPip
  • 1,871 posts

Posted 06 March 2006 - 11:41 PM

Here is a very good page about ServerXMLHTTP: Frequently asked questions about ServerXMLHTTP. One of the things it hilights is that ServerXMLHTTP does not do automatic proxy discovery and that you may have to run proxycfg.exe first... this would explain your trouble I believe.

There is an older component called XMLHTTP that is also discussed in that article that does do automatic proxy detection. I believe it could also be used to do this discovery, but from my experience may need some additional error handling when used in AutoIt. I have not done any testing of this however.

Dale

Edit: fixed hyperlink



Is there anyway to connect to a proxy ? - I would have server name or IP, username, password and would have the port numbeer.

Or has this question already been asked and answered?

Thanks

"Sometimes you have to go back to where you started, to get to where you want to go."  "Everybody catches up with everyone, eventually"  "As you teach others, you are really teaching yourself." all by me. From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow."

Windows_error.gif

How to ask a Question Forum SearchWIKI FAQ Tutorials Original FAQ - AutoIt Snippets - Multple Guis - Interrupting a running functionAnother Send StringRegExp StringRegExp Help RegEX TesterONLINE HELP UDF's Wiki AutoIt PDF AutoItSetOption Macros Wiki Arrays AutoIt Snippets WrapperAutoit Docs SCITE SciteJump - BB MyTopicsProgramming UDFs AutoIt_101 UDFs Form - UDFTutorial - Tutorials - Documentation - IE.AU3Games? - FreeSoftwarePath_Online

 

Spoiler

#15 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,981 posts

Posted 07 March 2006 - 12:49 AM

Is there anyway to connect to a proxy ? - I would have server name or IP, username, password and would have the port numbeer.

Or has this question already been asked and answered?

Thanks

From above: "you may have to run proxycfg.exe first" -- see the FAQ referenced. Or use XMLHTTPRequest that does auto proxy discovery.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

 

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

 

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y
Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble


#16 nitekram

nitekram

    Ng1-Nf3

  • Active Members
  • PipPipPipPipPipPip
  • 1,871 posts

Posted 07 March 2006 - 03:22 AM

From above: "you may have to run proxycfg.exe first" -- see the FAQ referenced. Or use XMLHTTPRequest that does auto proxy discovery.

Dale


I read the information and it appears that you can grab the info from the registry for HKCU - is this correct? If that is the case I can write the info from there...to the HKLM without a reboot? Or would it be better to call this application from within the script, but then I would have to include it with the script as I am sure not everyone would have the proxycfg.exe installed - I had to download it. The reason for all this is I would like to be able to run programs like the ccweather.au3 at my work which has an proxy server (ISA).

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\programming>proxycfg

Current WinHTTP proxy settings under
HKEY_LOCAL_MACHINE\
SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\
WinHttpSettings :
Flags = PROXY_TYPE_DIRECT
Proxy Server = -not set-
Bypass List = -not set-

C:\programming>proxycfg -?
WinHTTP Proxy Configuration Tool
usage:
proxycfg -? : to view help information
proxycfg : to view current winhttp proxy settings (in HKLM)
proxycfg [-d] [-p <server-name> [<bypass-list>]]
-d : set PROXY_TYPE_DIRECT
-p : set PROXY_TYPE_PROXY, proxy server, and optional bypass list
proxycfg -u : to set winhttp proxy settings
from current user's manual setting (in HKCU)

Edited by nitekram, 07 March 2006 - 03:25 AM.

"Sometimes you have to go back to where you started, to get to where you want to go."  "Everybody catches up with everyone, eventually"  "As you teach others, you are really teaching yourself." all by me. From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow."

Windows_error.gif

How to ask a Question Forum SearchWIKI FAQ Tutorials Original FAQ - AutoIt Snippets - Multple Guis - Interrupting a running functionAnother Send StringRegExp StringRegExp Help RegEX TesterONLINE HELP UDF's Wiki AutoIt PDF AutoItSetOption Macros Wiki Arrays AutoIt Snippets WrapperAutoit Docs SCITE SciteJump - BB MyTopicsProgramming UDFs AutoIt_101 UDFs Form - UDFTutorial - Tutorials - Documentation - IE.AU3Games? - FreeSoftwarePath_Online

 

Spoiler




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users