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

后端 未结 4 1888
夕颜
夕颜 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:37

    The reason Uri.IsWellFormedUriString("htttp://www.google.com", UriKind.Absolute) returns true is because it is in a form that could be a valid Uri. URI and URL are not the same.

    See: What's the difference between a URI and a URL?

    In your case, I would check that new Uri("htttp://www.google.com").Scheme was equal to http or https.

提交回复
热议问题