I need to check if a given URL (which is not necessarily prefixed with http or https) is HTTP or HTTPs.
Is this possible in vb.net ?
If the user gives just stackoverflow.com without any prefix, I must be able to identify that it is an HTTP one
I need to check if a given URL (which is not necessarily prefixed with http or https) is HTTP or HTTPs.
Is this possible in vb.net ?
If the user gives just stackoverflow.com without any prefix, I must be able to identify that it is an HTTP one
Try this:
In case that the url is plain without http/https check it with the below code:
'Validates a URL.
Function ValidateUrl(url As String) As Boolean
Dim validatedUri As Uri = Nothing
If (Uri.TryCreate(url, UriKind.Absolute, validatedUri)) Then
Return (validatedUri.Scheme = Uri.UriSchemeHttp Or validatedUri.Scheme = Uri.UriSchemeHttps)
End If
Return False
End Function
And then do something if http/https exists:
Dim u as new System.Uri("http://www.hello.com")
If u.Scheme = "http" Then
..do something..
Else
..do something else..