我正在尝试使用 telnet 连接 HTTP 服务器,但它失败了

时间:2021-02-04 12:54:23

标签: http networking tcp protocols

我正在学习 HTTP 协议。我已选择此站点进行实验:http://www.testingmcafeesites.com/testcat_ac.html

我已经屏蔽了我的防火墙。打开命令提示符并给出以下命令:

telnet testingmcafeesites.com 80

那行得通,然后我给这个:

GET / HTTP/1.1
Host: testingmcafeesites.com

我也试过:

GET / testcat_ac.html HTTP/1.1
Host: testingmcafeesites.com

但这也不起作用。 返回:

 HTTP/1.1 400 Bad Request
Content-Type: text/html
Content-Length: 173
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>Avi Vantage/</center>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

改为发送:

GET / HTTP/1.1
Host: testingmcafeesites.com

GET /testcat_ac.html HTTP/1.1
Host: testingmcafeesites.com

注意删除了 /testcat_ac.html 之间的空格。以及 Host 标头之后的额外空行。 HTTP 请求被 2 个 CRLF 换行符终止:

GET / HTTP/1.1<CRLF>
Host: testingmcafeesites.com<CRLF>
<CRLF>
GET /testcat_ac.html HTTP/1.1<CRLF>
Host: testingmcafeesites.com<CRLF>
<CRLF>