Comparing HTTP and HTTPS URIs

added by DotNetKicks
12/7/2017 2:09:55 PM

1 Kicks, 290 Views

Working with URIs is a regular exercise when we crawl the web. Consequently, comparing HTTP and HTTPS URIs quickly becomes an interesting challenge. Fortunately, .NET has us covered with the Uri.Compare(Uri, Uri, UriComponents, UriFormat, StringComparison) Method [TestMethod] public void CompareHttpAndHttpsURIsTest() { var http = new Uri(""); var https = new Uri(""); var result = Uri.Compare(http, https, UriComponents.Host | UriComponents.PathAndQuery, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); Assert.IsTrue(result == 0); } The next challenge, will probably be around comparing query strings.