static string GetPageSource(string URL)
{
Uri uri = new Uri(URL); HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();
hwReq.Credentials = CredentialCache.DefaultCredentials;
hwReq.Method = "Get"; hwReq.KeepAlive = false; StreamReader reader = new StreamReader(hwRes.GetResponseStream(), System.Text.Encoding.Default); return reader.ReadToEnd();
}
我用这个函数获取出来的源文件和鼠标右击时候的源文件不一样,不知道是怎么回事,请帮忙
{
Uri uri = new Uri(URL); HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();
hwReq.Credentials = CredentialCache.DefaultCredentials;
hwReq.Method = "Get"; hwReq.KeepAlive = false; StreamReader reader = new StreamReader(hwRes.GetResponseStream(), System.Text.Encoding.Default); return reader.ReadToEnd();
}
我用这个函数获取出来的源文件和鼠标右击时候的源文件不一样,不知道是怎么回事,请帮忙
而用WebRequest是通过程序
他们两者之间的处理机制不同吧
/// <summary>
/// 根据链接地址 获取 Html文本
/// </summary>
public static string Get_Html(string Url)
{
System.Net.WebClient wc = new System.Net.WebClient();
Byte[] pageData = wc.DownloadData(Url );
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
return System.Text.Encoding.Default.GetString(pageData);
}
这位兄弟,不行啊,还是不一样