C#, Is there a better way to verify URL formatting than IsWellFormedUriString?

后端 未结 4 1893
夕颜
夕颜 2021-02-08 05:09

Is there a better/more accurate/stricter method/way to find out if a URL is properly formatted?

Using:

bool IsGoodUrl = Uri.IsWellForm         


        
4条回答
  •  被撕碎了的回忆
    2021-02-08 05:23

    Technically, htttp://www.google.com is a properly formatted URL, according the URL specification. The NotSupportedException was thrown because htttp isn't a registered scheme. If it was a poorly-formatted URL, you would have gotten a UriFormatException. If you just care about HTTP(S) URLs, then just check the scheme as well.

提交回复
热议问题