Casomani dovete studiarvi un protocollo che usa gli HEADER HTTP il modo migliore per visualizzare le risposte di un server è quello di usare una shell ed un client telnet.

Il funzionamento è banale, prima di tutto facciamo aprire una sessione telnet sul server che ospita il sito/applicazione

CODE:
  1. fullo@tartar# telnet miohost.com 80

a questo punto in sessione iniziamo a fare un GET dell'url ReST che ci interessa, specificando il protocollo da usare ed indichiamo l'host di riferimento seguito da un doppio invio.

CODE:
  1. fullo@tartar# telnet miohost.com 80
  2. Trying 212.235.215.666...
  3. Connected to miohost.com (212.235.215.666).
  4. Escape character is '^]'.
  5. GET /api/v1/blogs;id=666/ HTTP/1.1                                       
  6. host: miohost.com

il risultato sarà quindi:

CODE:
  1. HTTP/1.1 200 OK
  2. Connection: close
  3. Content-Length: 148
  4. Expires: Tue, 08 May 2007 10:57:13 GMT
  5. Vary: Cookie
  6. Last-Modified: Tue, 08 May 2007 09:57:13 GMT
  7. ETag: dbdfe92c32166b674a94911ae7a22e14
  8. Cache-Control: max-age=3600
  9. Date: Tue, 08 May 2007 09:57:13 GMT
  10. Content-Type: text/xml
  11. Server: lighttpd/1.4.13
  12. ...

a questo punto possiamo comodamente studiare cosa viene restituito negli HEADER HTTP per lavorare (ad esempio) su un client che supporti il conditional get... :)

ciuaz

Tagged with:
 

5 Responses to Leggere gli HEADER HTTP con Telnet

  1. Marco says:

    Se non ti interessa la sessione interattiva puoi usare anche il comando netcat. Ad esempio:

    echo -e “GET /api/v1/blogs;id=666/ HTTP/1.1\nhost: miohost.com” | nc miohost.com 80

  2. fullo says:

    ottimo suggerimento! non avevo minimamente pensato a netcat

  3. Cesare says:

    Al posto di GET, che restituisce anche l’intero contenuto della pagina, si può usare HEAD, che restituisce invece i soli header :)

  4. DanKan says:

    Non è che avete un esempio anche in windows?
    Purtroppo le mie basi di linux sono ormai inutilizzabili…

  5. piefav says:

    e nel caso dovessi autenticarmi con utente e password ?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

phpDay 15.16 Maggio 2009 a Verona