Reputation: 3398
After parsing http traffic I noticed that the Domains I retrieved are incorrect.
Uri www.youtube.com./somepath/index.html
I've used the following code:
var ub = new UriBuilder("www.youtube.com.");
var u = ub.Uri;
Console.WriteLine(u.Host);
Is there an easy way to fix this? I don't think the . should be in the Host.
Upvotes: 0
Views: 240
Reputation: 19457
You may not have the problem that you think that you do!
Referring to the question Why is to.
a valid domain name?, the accepted answer begins with:
The final dot is part of the fully qualified domain name.
Whether the browser actually resolves a domain name with a trailing period seems to depend on the domain name. For instance, this URL is displayed by both Firefox 26 and Internet Explorer 9:
http://www.youtube.com./yt/about/
^
But this URL does not display:
http://stackoverflow.com./about
^
To confirm the legitimacy of these two domain names, I passed them both to nslookup
:
nslookup www.youtube.com.
nslookup stackoverflow.com.
And indeed, I found that each of the domain names resolved.
So, it seems that using your browser does not appear to be the authoritative method for validating a domain name by itself.
As to why certain URLs resolve in a browser with a period at the end of the domain name while others do not, that appears to be the basis for another question.
Upvotes: 0
Reputation: 1544
You can use this for removing beginning as well as trailing (.) dots:
string url = "www.youtube.com.";
url = url.trim(".");
Upvotes: 1