使用 telnet 获取网站标题

MyU*_*nix 7 http telnet

我有一个问题,是否可以使用 telnet 获取网站的标题?网站看起来像这样domain.name.server.com/~USER(只是示例)。我想通过 telnet 获取它的标题。

telnet domain.name.server.com/~USER 80 <-- 不起作用

telnet domain.name.server.com 80工作,但我需要得到〜用户。有没有可能做到这一点?

Tho*_*ner 19

telnet domain.name.server.com 80然后使用

HEAD /~USER HTTP/1.1
Host: domain.name.server.com
Run Code Online (Sandbox Code Playgroud)

(然后你必须再打Enter一次。)

现在它应该向您显示此页面的标题。

以现实生活为例:

$ telnet unix.stackexchange.com 80                 
Trying 198.252.206.16...
Connected to unix.stackexchange.com.
Escape character is '^]'.
HEAD /questions/237635/using-telnet-to-get-website-header HTTP/1.1
Host: unix.stackexchange.com

HTTP/1.1 200 OK
Cache-Control: public, no-cache="Set-Cookie", max-age=60
Content-Length: 70679
Content-Type: text/html; charset=utf-8
Expires: Wed, 21 Oct 2015 19:27:43 GMT
Last-Modified: Wed, 21 Oct 2015 19:26:43 GMT
Vary: *
X-Frame-Options: SAMEORIGIN
X-Request-Guid: dbf9d0f6-0ca4-423f-98f0-4cdf2bf51bf1
Set-Cookie: prov=08886524-c640-40ad-a0ee-246db3219228; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
Date: Wed, 21 Oct 2015 19:26:43 GMT

Connection closed by foreign host.
Run Code Online (Sandbox Code Playgroud)

  • 您还应该包括`Host: unix.stackexchange.com`,以便服务器知道您想要哪个网站,当它作为 _virtual hosts_ 为多个站点提供服务时。 (6认同)
  • 如果你没有 `telnet`,你可以使用 `nc` 或 `netcat` 获得同样的东西(发行版的名称各不相同,并且有一个原始版本和 GNU 版本在使用)。 (3认同)
  • 为什么哦,你为什么在这里使用 HTTP/1.0?当前(以及合理使用 `Host:` 标头的原因)是 HTTP/1.1,其主要特性是基于名称的虚拟主机。 (2认同)