Recent

Author Topic: test if web site is valid  (Read 1305 times)

What I can do

  • Full Member
  • ***
  • Posts: 125
test if web site is valid
« on: January 10, 2025, 11:46:42 pm »
OS:Windows 10@64
Lazarus 3.4
Why do all these links report as not valid
yahoo.com
http://yahoo.com
http://httP://www.yahoo.com
NOTE: the second set of "//" was add automatically
I'm doing something wrong...

Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpclient  ,Opensslsockets
  3. //...
  4.  
  5. function IsURLValid(const URL: string): Boolean;
  6. var
  7.   HTTPClient: TFPHTTPClient;
  8. begin
  9.   Result := False;
  10.   HTTPClient := TFPHTTPClient.Create(nil);
  11.   try
  12.     try
  13.       HTTPClient.Get(URL);
  14.       // If we get here without an exception, the URL is likely valid
  15.       Result := True;
  16.     except
  17.       on E: EHTTPClient do
  18.         // URL not valid or other HTTP errors
  19.         Result := False;
  20.     end;
  21.   finally
  22.     HTTPClient.Free;
  23.   end;
  24. end;
  25.  
« Last Edit: January 10, 2025, 11:51:04 pm by What I can do »

TRon

  • Hero Member
  • *****
  • Posts: 3742
Re: test if web site is valid
« Reply #1 on: January 10, 2025, 11:54:36 pm »
http isn't valid for ages. The second url, is invalid by deifnition

Did you have redirection turned on ? because that also results in an error as per your example.
I do not have to remember anything anymore thanks to total-recall.

What I can do

  • Full Member
  • ***
  • Posts: 125
Re: test if web site is valid
« Reply #2 on: January 11, 2025, 02:03:08 am »
Hi TRon
yes the line
http://httP://www.yahoo.com
changes itself when I hit the post button
the original code is
http://www.yahoo.com
but this post utility adds the additional "//http:" for some reason

How do I turn redirection on?
is that a lazarus or browser thing?

TRon

  • Hero Member
  • *****
  • Posts: 3742
Re: test if web site is valid
« Reply #3 on: January 11, 2025, 03:17:43 am »
but this post utility adds the additional "//http:" for some reason
Ah, sorry. I missed your edit. Sorry about that. Next time just paste the url as text (not a link) or use code tags.

Quote
How do I turn redirection on?
Code: Pascal  [Select][+][-]
  1. HTTPClinet.AllowRedirect:= true
  2.  

See also https://www.freepascal.org/daily/packages/fcl-web/fphttpclient/tfphttpclient.html or in particular https://www.freepascal.org/daily/packages/fcl-web/fphttpclient/tfphttpclient.allowredirect.html

The wiki on fphttpclient can also be helpful

Quote
is that a lazarus or browser thing?
It is a TFPHTTPClient class thing  :)

Because you used the on Except handler in the example TFPHTTPClient will silently fail exceptions (as instructioned) so that you never see the 'error'. So as a hint when running into issues always display the exception message in order to get feedback on what is actually happening.
I do not have to remember anything anymore thanks to total-recall.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1447
    • Lebeau Software
Re: test if web site is valid
« Reply #4 on: January 11, 2025, 04:19:26 am »
http isn't valid for ages.

That is a bit misleading. There are plenty of sites that are still using HTTP and not HTTPS. Just because HTTPS is popular doesn't necessarily mean that every site needs/uses it.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

TRon

  • Hero Member
  • *****
  • Posts: 3742
Re: test if web site is valid
« Reply #5 on: January 11, 2025, 04:24:44 am »
That is a bit misleading. There are plenty of sites that are still using HTTP and not HTTPS. Just because HTTPS is popular doesn't necessarily mean that every site needs/uses it.
You are correct Remy. It is misleading because you are right: there still exists websites that accept http. My apologies.

However, major browser builders have mandated that we are not allowed to access those anymore. As a result the number of websites that are accessible by http seem to decline as a result.

I do not have to remember anything anymore thanks to total-recall.

Thaddy

  • Hero Member
  • *****
  • Posts: 16300
  • Censorship about opinions does not belong here.
Re: test if web site is valid
« Reply #6 on: January 11, 2025, 10:42:15 am »
http isn't valid for ages. The second url, is invalid by deifnition
Wrong, still valid.
three of my static websites:
http://thaddy.com
http://thaddy.org
http://thaddy.nl

If you happen to have a certificate installed issued by me, you will be redirected to a https:// website. The certificate acts as a lock-keypass, it is not ssl, that comes after. Logging in with password is not possible, only with my certificate.
If you try https on these sites *without* my certificate, you get a self-signed dummy.

Since the http:// sites are 100% static, there is no need for https.
« Last Edit: January 11, 2025, 10:48:06 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

TRon

  • Hero Member
  • *****
  • Posts: 3742
Re: test if web site is valid
« Reply #7 on: January 11, 2025, 06:34:32 pm »
Wrong, still valid.
No idea in what universe the url ...
Code: [Select]
http://httP://www.yahoo.com
.. is valid, but hey if it does in yours then I am happy for you (forum software seems to agree with you) ;D

But it is dead horse as TS already mentioned the reason why (as already stated I simply and initially missed it). As well as that modern established browser (by default some not even allowing to change that behaviour) forces https on the url no matter what (and as a result you are unable to access the website using http).
« Last Edit: January 11, 2025, 06:54:11 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

jamie

  • Hero Member
  • *****
  • Posts: 6776
Re: test if web site is valid
« Reply #8 on: January 11, 2025, 06:51:06 pm »
That is a bit misleading. There are plenty of sites that are still using HTTP and not HTTPS. Just because HTTPS is popular doesn't necessarily mean that every site needs/uses it.
You are correct Remy. It is misleading because you are right: there still exists websites that accept http. My apologies.

However, major browser builders have mandated that we are not allowed to access those anymore. As a result the number of websites that are accessible by http seem to decline as a result.

I hope that is not the case, I use http//.. to connection to hardware using the default browser in the pc. That would be a tragic event if that stopped.
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 3742
Re: test if web site is valid
« Reply #9 on: January 11, 2025, 06:56:32 pm »
I hope that is not the case, I use http//.. to connection to hardware using the default browser in the pc. That would be a tragic event if that stopped.
Unfortunately it is. And indeed it is a PITA as I am also unable to access some devices on my local network in that way. On some of my systems I have to resort to either a custom solution or use an older browser that still supports http. Not every (recent) browser allows to override the behaviour of forcing https. It the same annoying behaviour as that some browsers removed ftp support.
« Last Edit: January 11, 2025, 06:59:48 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

dseligo

  • Hero Member
  • *****
  • Posts: 1443
Re: test if web site is valid
« Reply #10 on: January 11, 2025, 07:08:05 pm »
Unfortunately it is. And indeed it is a PITA as I am also unable to access some devices on my local network in that way. On some of my systems I have to resort to either a custom solution or use an older browser that still supports http. Not every (recent) browser allows to override the behaviour of forcing https.

I just tried to connect to my router using http://10.1.1.1 with Firefox, Edge and Chrome (all latest versions) and all of them works. Am I missing something?

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1447
    • Lebeau Software
Re: test if web site is valid
« Reply #11 on: January 11, 2025, 10:40:14 pm »
However, major browser builders have mandated that we are not allowed to access those anymore. As a result the number of websites that are accessible by http seem to decline as a result.

That is absolutely not true. All  browsers handle HTTP and HTTPS equally just fine. The browser vendors are not mandating anything, and they are not the ones driving sites away from HTTP towards HTTPS. That is wholly up to the site owners to decide.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Thaddy

  • Hero Member
  • *****
  • Posts: 16300
  • Censorship about opinions does not belong here.
Re: test if web site is valid
« Reply #12 on: January 11, 2025, 11:32:00 pm »
Indeed, all browsers that i know of, al the major ones.
If I smell bad code it usually is bad code and that includes my own code.

Thaddy

  • Hero Member
  • *****
  • Posts: 16300
  • Censorship about opinions does not belong here.
Re: test if web site is valid
« Reply #13 on: January 11, 2025, 11:33:49 pm »
Unfortunately it is.
Fortunately it is not. Come on Ron, admit you are wrong.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018