Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

To access www.ietf.org/rfc.html, I entered the following commands:

telnet www.ietf.org 80 > log
get /rfc.html HTTP/1.1
Host: www.ietf.org

While I was in the midst of typing the 3rd command, the following message displayed :

Connection closed by foreign host.

The log entry was :

> Trying 64.170.98.30...
Connected to www.ietf.org.
Escape character is '^]'.
HTTP/1.1 400 Bad Request
Date: Thu, 27 Dec 2012 09:32:01 GMT
Server: Apache/2.2.10 (Linux/SUSE) mod_ssl/2.2.10 OpenSSL/0.9.8h PHP/5.2.13 with     Suhosin-Patch mod_python/3.3.1 Python/2.6 mod_wsgi/3.3 mod_perl/2.0.4 Perl/v5.10.0
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

So what's the problem?

share|improve this question
    
I think you should use wget www.ietf.org/rfc.html. –  Eric Carvalho Dec 27 '12 at 12:09

1 Answer 1

Assuming you are able to retrieve the file with wget as Eric Carvalho suggested (wget www.ietf.org./rfc.html), the problem is likely just that the web server hung up on you because you didn't send your request fast enough.

Each time a page is retrieved, a separate TCP connection is made to the web server's HTTP port. Once connected, if you don't send a command soon enough, the server will assume that the connection is abandoned (which happens quite often, even though most web browsers minimize it by properly terminating their TCP connections when they're done).

If your goal is just to download the page and look at it, you should use wget, curl, or fetch instead of telnet. You can view the file on the command line with cat or less.

If your goal is to play around with using telnet to access web content--for example, to enhance your understanding of HTTP--then you might consider writing a program or script (it could even be a shell script) that acts as a simple front-end for telnet by taking the server's name and HTTP commands, and then connects to the server, sending the command(s) quickly thereafter.

share|improve this answer
    
Could it be a server-specific problem? Because I tried the following and it worked: telnet www.nytimes.com 80 >log get /pages/world/index.html HTTP/1.1 host: www.nytimes.com Connection closed by foreign host. And I took my sweet time typing the commands. –  Copperfield Dec 29 '12 at 13:40
    
The log contained the full,correct html page.Could the issue be related to the connection parameters set by the server? –  Copperfield Dec 29 '12 at 13:48
    
@Copperfield Yes, it could be a problem with the server. If everything had been working properly, I think you should have seen a 408 timeout error. –  Eliah Kagan Dec 29 '12 at 15:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.