I have a web service that acts as an interface between a farm of websites and some analytics software. Part of the analytics tracking requires harvesting the page title. Rather than passing it from the webpage to the web service, I would like to use HTTPWebRequest
to call the page.
I have code that will get the entire page and parse out the html to grab the title tag but I don't want to have to download the entire page to just get information that's in the head.
I've started with
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url");
request.Method = "HEAD";
Great idea, but a HEAD request only returns the document's HTTP headers. This does not include the title element, which is part of the HTTP message body.
So I would have to go with something like...
Try this:
If you don't want to request the entire page, you can request it in pieces. The http spec defines a http header called Range. You would use it like below:
Range: bytes=0-100
You can look through the returned content and find the title. If it is not there, then request Range: 101-200 and so on until you get what you need.
Obviously, the web server needs to support range, so this may be hit or miss.