HttpWebResponse how does it end

N

Nuno Magalhaes

In pages that there is no content length, how does HttpWebResponse
knows where the page ends? And what kind of objects/methods does it
retrieve? Does it only retrieve the initial page without any images,
i.e., does it only makes one "GET / HTTP/1.1\r\n\r\n"?

Because I'm doing some projects on a webclient (to measure some
statistic times) and the total bytes get byte HttpWebResponse are lower
than the total objects I get via socket way.

In other words, does HttpWebResponse only gets the specified html page
without any objects? When there is no Content-Length property, how does
it know when the page ends?

All the replies I got, were unclear about this matter. Sorry for the
repost.

Thanks for any reply,
Nuno Magalhaes.
 
K

Kevin Spencer

I'm not following you. It sounds as though you are asking several different
questions, but mixing them together. One is about the HttpWebResponse class,
and the other is about the HTTP protocol.

A single HttpWebResponse is going to encapsulate one HTTP response. If an
HTML document sent in a Response has images in it, for example, the initial
Response will not contain any images, but image tags in HTML for the page
returned. Each image tag identifies the URL for that image, and a separate
Request must be sent to the server for each additional resource.

As to your description regarding the "total bytes" from an HttpWebResponse
(I think) versus "socket way" doesn't contain enough information about what
"socket way" refers to to, what "total bytes" refers to, or what "total
objects" refers to, to make a guess as to what exactly you're talking about,
or what is going on.

As to your question about how a .Net client application (not an
HttpWebResponse) knows when "the page" ends, you might want to read up on
the HTTP protocol. The following is a nice, fairly succinct explanation of
the HTTP protocol:

http://www.jmarshall.com/easy/http/

It is important to distinguish between the client application that is
processing the Response and the HttpWebResponse object. The HttpWebResponse
object does not create the Response at all. It is created on a .Net client
when an HTTP Response is received from the server. It is simply a class that
encapsulates all of the HTTP Response message received by the client.

It also might be noted that an HttpWebResponse class instance is not an HTTP
Response message, but a class that encapsulates the message. The message
itself is simply a text stream that is sent from the server.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
N

Nicholas Paldino [.NET/C# MVP]

Nuno,

When you view a page in a web browser, the browser parses the HTML that
comes from the server, and fetches separate requests for the items in the
page which need to be loaded.

HttpWebRequest will not do this. If you want to do this, you will need
to parse the content, resolve all relative urls, and then fetch the items in
the page.

As for not knowing when there is no content length property, I believe
that the connection is closed, which tells the client that there is no more.

Hope this helps.
 

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