与网站一起使用的桌面应用程序.
问题描述:
可以说我有一个用c#编写的Windows窗体应用程序.我想知道如何将该应用程序连接到网站?例如,如何获取< title>网站的任何网站并显示在我的应用程序上?
Lets say I have a windows form application programmed with c#. I want to know how can I connect this application to a website? For example how can I get the <title> of any website and display it on my application?
答
尝试HtmlAgilityPack
会帮到你..
不要忘记在项目中添加HtmlAgilityPack.dll.
try HtmlAgilityPack
it will help you..
don''t forgot to add HtmlAgilityPack.dll in your project.
尝试一下:
Try this:
using System.Xml;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Net;
/*...........................*/
HttpWebRequest myReq = ( HttpWebRequest )WebRequest.Create( "http://www.contoso.com/" );
myReq.AllowAutoRedirect = true;
myReq.MaximumAutomaticRedirections = 5;
XNode result;
using( var responseStream = myReq.GetResponse( ).GetResponseStream( ) ) {
result = XElement.Load( responseStream );
}
var title = result.XPathSelectElement( "//title" ).Value;