Ejemplo peticiones y respuestas telnet por el puerto 80
Hacemos telnet al servidor al que queremos hacer la petición por el puerto 80. Si tiene el puerto 80 activo le vamos a realizar la petición (método con la URI y la versión) e introducimos Enter. Finalmente introducimos el host sobre el que queremos realizar la petición. Nota Importante: Una vez introducido el host hay que dar dos veces al enter.
Obtenermos la cabecera y contenido de la página principal de profesordeinformatica.com con el método GET:
$ telnet www.profesordeinformatica.com 80Trying 217.160.242.178...
Connected to www.profesordeinformatica.com.
Escape character is '^]'.
GET / HTTP/1.1
Host:www.profesordeinformatica.com
HTTP/1.1 200 OK Date: Sun, 03 Nov 2013 05:29:18 GMT Server: Apache X-Powered-By: PHP/5.2.17 Transfer-Encoding: chunked Content-Type: text/html <!DOCTYPE html> <!--[if lt IE 7 ]><html class="ie ie6" lang="es"> <![endif]--> <!--[if IE 7 ]><html class="ie ie7" lang="es"> <![endif]--> <!--[if IE 8 ]><html class="ie ie8" lang="es"> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--><html lang="es"> <!--<![endif]--> <head> ...........
Obtenemos la cabecera de localhost:
$ telnet localhost 80Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HEAD / HTTP/1.1
Host:localhost
HTTP/1.1 200 OK Date: Sun, 03 Nov 2013 05:34:47 GMT Server: Apache/2.2.22 (Ubuntu) Last-Modified: Mon, 14 Oct 2013 17:56:15 GMT ETag: "66091b-b1-4e8b72f36510b" Accept-Ranges: bytes Content-Length: 177 Vary: Accept-Encoding Content-Type: text/html X-Pad: avoid browser bug
Para ver los métodos que tenemos activados en localhost. En nuestro caso OPTIONS,GET,HEAD,POST .
$ telnet localhost 80 Trying 127.0.0.1...Connected to localhost.
Escape character is '^]'.
OPTIONS / HTTP/1.1
Host:localhost
HTTP/1.1 200 OK Date: Sun, 03 Nov 2013 05:37:41 GMT Server: Apache/2.2.22 (Ubuntu) Allow: OPTIONS,GET,HEAD,POST Vary: Accept-Encoding Content-Length: 0 Content-Type: text/html
Otra forma de realizar peticiones es utilizando el comando nc:
$ nc -vv 127.0.0.1 80Connection to 127.0.0.1 80 port [tcp/http] succeeded!
GET / HTTP/1.1
Host:localhost
HTTP/1.1 200 OK Date: Sun, 03 Nov 2013 05:59:09 GMT Server: Apache/2.2.22 (Ubuntu) Last-Modified: Mon, 14 Oct 2013 17:56:15 GMT ETag: "66091b-b1-4e8b72f36510b" Accept-Ranges: bytes Content-Length: 177 Vary: Accept-Encoding Content-Type: text/html X-Pad: avoid browser bug <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html>