使用的HttpWebRequest获取远程文件的标题 [英] Use HTTPWebRequest to get remote page's title
问题描述
我有作为网站的一个农场和一些分析软件之间的接口的Web服务。在分析跟踪的部分需要收获的页面标题。而不是从网页到Web服务传递给它,我想用的HttpWebRequest
来调用页面。
我有code,将让整个页面,并解析出HTML抢标题标签,但我不希望有下载整个页面只得到这是在头部信息。
我已经开始与
HttpWebRequest的要求=(HttpWebRequest的)HttpWebRequest.Create(URL);
request.Method =HEAD;
好主意,但一个的 HEAD请求仅返回文档的HTTP标头。这不包括title元素,它是HTTP消息主体的一部分。
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.
这篇关于使用的HttpWebRequest获取远程文件的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!