Getting the HTTP Content-Length Parameter

N

Nuno Magalhaes

I'm doing a "low level" project that consists on monitoring certain QoS
parameters such as: Time to resolve dns, time to connect, time to
receive data, time to receive all web page, time to close connection,
between others...
Since that I cannot use any higher level procedures such as WebClient,
HTTPWebRequest and Response.

The problem is that I'm not getting the "Content-Length" parameter in
the HTTP response header. Do you know if passing to server "GET /
HTTP/1.1\n\n" is enough to receive the "Content-Length" parameter,
because I'm not receiving it.

Any hints on this matter,
Any expert on HTTP headers and servers?

Thanks for any reply,
Nuno Magalhaes.

P.S.: One person told me here that using "HEAD / HTTP/1.1\r\n" would
give me the content-length of the html page. Is that true?
 
J

Joerg Jooss

Nuno said:
I'm doing a "low level" project that consists on monitoring certain
QoS parameters such as: Time to resolve dns, time to connect, time to
receive data, time to receive all web page, time to close connection,
between others...
Since that I cannot use any higher level procedures such as WebClient,
HTTPWebRequest and Response.

The problem is that I'm not getting the "Content-Length" parameter in
the HTTP response header. Do you know if passing to server "GET /
HTTP/1.1\n\n" is enough to receive the "Content-Length" parameter,
because I'm not receiving it.

Any hints on this matter,
Any expert on HTTP headers and servers?

Nuno, please realize that reimplementing a complete HTTP stack isn't
trivial at all. You can post your questions in 5 minutes intervals here
and still the answers won't become more encouraging...

The first thing to understand is that HTTP is based on a spec. If you
need to deal with, read it:
http://www.w3.org/Protocols/rfc2616/rfc2616.html

To give you a headstart, a Content-Length header is not a required
reponse header, *if* the response contains a Connection: close header
(which terminates the conversation) or uses Transfer-Encoding: chunked
(which means the response is split up into several fragments, usually
done for large reponse bodies such all file donwloads).
P.S.: One person told me here that using "HEAD / HTTP/1.1\r\n" would
give me the content-length of the html page. Is that true?

No, HEAD will only give you the same response as GET without the
response body. As far as headers are concerned, the spec says:
"The metainformation contained in the HTTP headers in response to a
HEAD request SHOULD be identical to the information sent in response to
a GET request."

But a quick test shows that this only a SHOULD, and *should not* be
relied upon (pun somewhat intended).

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top