Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

networking - I am trying to connect a HTTP server using telnet but it's failing

I am learning HTTP protocols. I have choose this site for experiment: http://www.testingmcafeesites.com/testcat_ac.html

I have blocked my firewall. Opened command prompt and gave following command:

telnet testingmcafeesites.com 80

that works, then i give this:

GET / HTTP/1.1
Host: testingmcafeesites.com

I have also tried:

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

but that also doesn't work. returns:

 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>
question from:https://stackoverflow.com/questions/66046067/i-am-trying-to-connect-a-http-server-using-telnet-but-its-failing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Send this instead:

GET / HTTP/1.1
Host: testingmcafeesites.com

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

Note the space removed between / and testcat_ac.html. And the extra empty line after the Host header. An HTTP request is terminated by 2 CRLF line breaks:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...