标准化URI以仅提取域名的最佳方法是什么? [英] What is best way to normalize an URI to extract just the domain name?

查看:36
本文介绍了标准化URI以仅提取域名的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

http://www.google.co.uk
www.google.co.uk
google.co.uk

将全部转换为:

google.co.uk

我本来想使用System.Uri类,但这似乎只接受带有方案的url.

I would have liked to use the System.Uri class but this only seems to accept urls with a scheme.

推荐答案

尝试使用此代码

var url = "";
if (! url.Contains("://"))
{
        Url = "http://" + url;
}

var result = new Uri(url).Host;

这篇关于标准化URI以仅提取域名的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆