c# - 为什么 Dns.GetHostAddresses 无法获取 https ://google. com 的 IP 地址?

标签 c# dns

我正在尝试使用以下代码获取“https://google.com”的主机地址:

 var host = Dns.GetHostAddresses("https://google.com");

但我得到一个异常(exception):

{"No such host is known"}

我想知道,为什么我无法获取条目?

最佳答案

不要提供 https://,只需提供 google.com,因为 https:// 不是主机名的一部分。

 var host = Dns.GetHostAddresses("google.com");

我发现对 URL 部分的解释非常好 here摘录如下。

http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#00h02m30s

以下是 url 的一些组成部分:

  • The protocol is http. Other protocols include https, ftp, etc.
  • The host or hostname is video.google.co.uk.
  • The subdomain is video.
  • The domain name is google.co.uk.
  • The top-level domain or TLD is uk. The uk domain is also referred to as a country-code top-level domain or ccTLD. For google.com, the TLD would be com.
  • The second-level domain (SLD) is co.uk.
  • The port is 80, which is the default port for web servers. Other ports are possible; a web server can listen on port 8000, for example. When the port is 80, most people leave out the port.
  • The path is /videoplay. Path typically refers to a file or location on the web server, e.g. /directory/file.html
  • This URL has parameters. The name of one parameter is docid and the value of that parameter is -7246927612831078230. URLs can have lots parameters. Parameters start with a question mark (?) and are separated with an ampersand (&). See the “#00h02m30s”? That’s called a fragment or a named anchor. The Googlers I’ve talked to are split right down the middle on which way to refer it. Disputes on what to call it can be settled with arm wrestling, dance-offs, or drinking contests. 🙂 Typically the fragment is used to refer to an internal section within a web document. In this case, the named anchor means “skip to 2 minutes and 30 seconds into the video.” I think right now Google standardizes urls by removing any fragments from the url.

关于c# - 为什么 Dns.GetHostAddresses 无法获取 https ://google. com 的 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42693106/

相关文章:

c# - 内部抽象类 : how to hide usage outside assembly?

c# - 检查我的电脑是否有bios密码(通过VB/C#)

.net - 为什么我本地 WCF 客户端的 IP 不是 127.0.0.1?

dns - 如何使用 mailgun 验证 openshift 域?

linux -/etc/hosts 文件,其中解析的 dns 机器与其他名称相关联

c# - 使用 .NET 连接到 AS400

c# - 使用google api获取给定地址的经纬度问题

c++ - c/c++ for windows 中的 DNS 服务器

c# - 线类报表、线日报表

c# - 在 TCP 套接字数据发送 C# 之间获取恒定延迟