19

I am using Ubuntu telnet client. I am trying to send 2 lines over the telnet connection that I have made.

For example:

> telnet en.wikipedia.org 80
  GET /wiki/Main_Page http/1.1   <CR>                            // line 1
  Host: en.wikipedia.org         <CR>                            // line 2
  <CR>

where CR stands for carriage return. The problem is after typing line 1, press CR , that line will be sent over the telnet connection. I can not be able to send line 2 immediately after that.

Can somebody help?

  • Have you tried escaping the with a '\', i.e., GET /wiki/Main_Page http/1.1 \ – corriganjc Nov 11 '10 at 21:26
  • It is a bit late to point this out but - like @Mark hinted in his comment - you MUST not send just a `\r` character on it's own. if you are sending a normal end of line you must send a `\r\n` (Carriage-Return + New Line) pair of characters - if you intend to send only a Carriage-Return to move the *current* position to the start of the line **without advancing to the next line** then you must send `\r\0` i.e. a Carriage-Return and then a Null character. – SlySven May 24 '20 at 04:16

4 Answers4

41

You can set the crlf option in telnet. You can do this by, during your telnet session, typing the escape character (^]), and then "toggle crlf". A perhaps cleaner way is to specify this before making the connection:

$ telnet
telnet> toggle crlf
Will send carriage returns as telnet <CR><LF>.
telnet> open mailhost smtp
Ian Robertson
  • 1,312
  • 1
  • 13
  • 14
13

When you are operating in a Telnet client, sending a newline or carriage return control code to the client, will send it directly to the host.

The easiest way to do what you want would be to copy/paste the HTTP GET request from another text editor, so that the newlines are embedded in the text.

ocodo
  • 29,401
  • 18
  • 105
  • 117
  • 3
    to clarify, it seems that pressing the enter-key when in a telnet session will always send either `\r` or `\r\n`. The only way to transmit just `\n` at the end of a line is to copy/paste it from somewhere else like an editor. – Mark Feb 07 '13 at 20:05
2

Try Ctrl+Shift+Enter I tried on Mac OS Mojave Terminal.

mcbill
  • 367
  • 3
  • 12
1

The real reason is this.

For windows users, it is well known that cmd is case-insensitive by default.

But in windows, the editing interface of telnet is case sensitive!

Same for unix, Ubuntu, etc.

If you enter: GET /wiki/Main_Page http/1.1, you will get the wrong result.

If you enter: GET /wiki/Main_Page HTTP/1.1, you will get the result you want.

This telnet problem took me hours, damn it.

zss
  • 21
  • 1