Comparing HTTP and HTTPS URIs
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("http://www.microsoft.com"); var https = new Uri("https://www.microsoft.com"); 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. Because this gets complicated quickly, I’ll leave this one for another time.