C#, Is there a better way to verify URL formatting than IsWellFormedUriString? -
is there better/more accurate/stricter method/way find out if url formatted?
using:
bool isgoodurl = uri.iswellformeduristring(url, urikind.absolute); doesn't catch everything. if type htttp://www.google.com , run filter, passes. notsupportedexceptionlater when calling webrequest.create.
this bad url make past following code (which other filter find):
uri nurl = null; if (uri.trycreate(url, urikind.absolute, out nurl)) { url = nurl.tostring(); }
the reason uri.iswellformeduristring("htttp://www.google.com", urikind.absolute) returns true because in form valid uri. uri , url not same.
see: what's difference between uri , url?
in case, check new uri("htttp://www.google.com").scheme equal http or https.
Comments
Post a Comment