Jump to content

Recommended Posts

Posted (edited)

Example

$sURL = "http://test/21-04-2014"
InetGetSize($sURL)
If @error Then
    ConsoleWrite("Invalid URL" & @CRLF)
Else
    ConsoleWrite("Valid URL" & @CRLF)
EndIf 

Regards :)

Phoenix XL

Edited by PhoenixXL

My code:

  Reveal hidden contents
PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted
  On 3/31/2014 at 7:20 AM, PhoenixXL said:

Example

$sURL = "http://test/21-04-2014"
InetGetSize($sURL)
If @error Then
    ConsoleWrite("Invalid URL" & @CRLF)
Else
    ConsoleWrite("Valid URL" & @CRLF)
EndIf 

Regards :)

Phoenix XL

Ace, never seen that before.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

But if the site is down and the URL is valid the code above will return False. I though a regular expression would have been suggested by PhoenixXL, but honestly I prefer _WinAPI_UrlIs() in WinAPIShPath.au3.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I think the answer to this will depend on what the OP means by "is valid" rather than trying to guess. Is valid can be a properly formatted string that is a URL, or a URL that actually exists versus a non-existent site/file/path.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)
  On 3/31/2014 at 1:17 PM, guinness said:

But if the site is down and the URL is valid the code above will return False. I though a regular expression would have been suggested by PhoenixXL, but honestly I prefer _WinAPI_UrlIs() in WinAPIShPath.au3.

Didn't knew about that

Anyways I'm getting conflicting results, is it the same for all

#include <WinAPIShPath.au3>

$sTest = "http://testinghg.com/"
_U($sTest)

$sTest = "http://test/21-04-2014"
_U($sTest)


Func _U($URL)

    MsgBox(0, $URL, "URLIs: " & _WinAPI_UrlIs ($sTest) & @CRLF & "IE: " & ((InetGetSize($sTest) = 0) ? "0" : "1"))

EndFunc   ;==>_U 
 
  On 3/31/2014 at 2:35 PM, BrewManNH said:

I think the answer to this will depend on what the OP means by "is valid" rather than trying to guess. Is valid can be a properly formatted string that is a URL, or a URL that actually exists versus a non-existent site/file/path.

 

That must be the conflicting results, then.

I think, these methods won't solve the problem, we will have to prefer something like on libcURL. InetGetInfo has never given me wrong results(till now at least) therefore I had relied on it. 

Regards :)

Phoenix XL

Edited by PhoenixXL

My code:

  Reveal hidden contents
PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

Based on the examples above.
I would personally go with the InetGetSize rather than _WinAPI_UrlIs. As Phoenix said it worked with great accurasy for me until no.

#include <WinAPIShPath.au3>
$sURL = "http://test/21-04-2014"
$_AZ = "abcdefghijklmnopqrstuvwxyz"
$_AZ = StringSplit($_AZ, "")
For $i = 1 To UBound($_AZ) -1
 $sURL &= $_AZ[$i]
;~  _WinAPI_UrlIs ($sURL)
 InetGetSize($sURL)
 If @error Then
  ConsoleWrite("Invalid URL" & @LF)
 Else
  ConsoleWrite("Valid URL" & @LF)
 EndIf
 $sURL = "http://test/21-04-2014"
Next
Posted

  On 3/31/2014 at 10:39 PM, AutID said:

 

Based on the examples above.

I would personally go with the InetGetSize rather than _WinAPI_UrlIs. As Phoenix said it worked with great accurasy for me until no.

#include <WinAPIShPath.au3>
$sURL = "http://test/21-04-2014"
$_AZ = "abcdefghijklmnopqrstuvwxyz"
$_AZ = StringSplit($_AZ, "")
For $i = 1 To UBound($_AZ) -1
 $sURL &= $_AZ[$i]
;~  _WinAPI_UrlIs ($sURL)
 InetGetSize($sURL)
 If @error Then
  ConsoleWrite("Invalid URL" & @LF)
 Else
  ConsoleWrite("Valid URL" & @LF)
 EndIf
 $sURL = "http://test/21-04-2014"
Next

Thanks a lot! ;) 

Posted

  On 3/31/2014 at 10:39 PM, AutID said:

 

Based on the examples above.

I would personally go with the InetGetSize rather than _WinAPI_UrlIs. As Phoenix said it worked with great accurasy for me until no.

#include <WinAPIShPath.au3>
$sURL = "http://test/21-04-2014"
$_AZ = "abcdefghijklmnopqrstuvwxyz"
$_AZ = StringSplit($_AZ, "")
For $i = 1 To UBound($_AZ) -1
 $sURL &= $_AZ[$i]
;~  _WinAPI_UrlIs ($sURL)
 InetGetSize($sURL)
 If @error Then
  ConsoleWrite("Invalid URL" & @LF)
 Else
  ConsoleWrite("Valid URL" & @LF)
 EndIf
 $sURL = "http://test/21-04-2014"
Next

And what if the URL is valid but the page has a size of 0?

The OP needs to confirm are they checking if a URL is valid and/or active? If it's the latter then why no one has recommended WinHttp with a HEAD request is beyond me.. 

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 4/1/2014 at 4:21 AM, guinness said:

And what if the URL is valid but the page has a size of 0?

Then the OP has to come up with something else.

In my opinion winhttp is the best solution but i only provided what the OP asked based on the examples provided in this thread.

I don't like InetGetSize function but i prefere it next to _WinAPI_UrlIs. Still a winhttp request is still the best solution, the fastest and the safest.

Posted

Why don't you like UrlIs()?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

All URLIs does is validates that the string is formatted as a correct URL, it doesn't verify that the URL actually points to anything.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted
  On 4/1/2014 at 5:26 PM, BrewManNH said:

All URLIs does is validates that the string is formatted as a correct URL, it doesn't verify that the URL actually points to anything.

I know what the function does, I am asking why is it bad if the sole purpose is to validate a URL? Also neither does InetGetSize().

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

What does InetGetSize return on a valid but empty file?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)
  On 4/1/2014 at 5:38 PM, BrewManNH said:

What does InetGetSize return on a valid but empty file?

 

Returned Valid for me, might require some time to refresh the file on the website so am not totally sure.

 

EDIT: returned the file size of "0" and said valid, tried with a random file name, returned "0" and said invalid, so I guess its working even with the 0 size

Edited by Palestinian
Posted

That was what I expected, but don't have any way of testing it as I don't have a website or an empty file on someone else's to check. ;)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

  On 4/1/2014 at 5:16 PM, guinness said:

Why don't you like UrlIs()?

Because the only thing it does is validate if a string is formatted as a correct url. Nothing to do with what OP is asking and nothing in relation with InetGetSize.

Thinking of it I don't even know why you proposed it.

And as I tested, InetGetSize will work correctly even with a size 0.

I still can't understand what are you searching in this thread but it is fine.

 

Posted (edited)

The op was asking to "test if a URL is valid", so that could be formatted correctly or resolves to an actual site. Did you not read the original question? It was only until post #7 that confirmation was made i.e. my suggestion was valid before post #7.

PS I am allowed to post here if I so wish. Same goes for yourself and everyone else.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

What is the point of checking if an URL is valid if it doesn't point to anything?

URL = Uniform Resource Locator

It is a string that constitutes a reference to a resource.

Understanding the above validating an URL means: Check if the "string" point to anything and NOT validate if a string is formatted as a correct url.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...