By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,950 Members | 1,585 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,950 IT Pros & Developers. It's quick & easy.

Getting the HTTP Content-Length Parameter

P: n/a
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?

Nov 27 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nuno Magalhaes wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 27 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.