日期:2014-05-18 浏览次数:20817 次
public static string GetHtml(string URL, string cookie, out string header, string server) { HttpWebRequest httpWebRequest; HttpWebResponse webResponse; Stream getStream; StreamReader streamReader; string getString = ""; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL); httpWebRequest.Accept = "*/*"; httpWebRequest.Referer = "http://www.xxxx.com.cn/Index/logincheck"; CookieContainer co = new CookieContainer(); co.SetCookies(new Uri(server), cookie); httpWebRequest.CookieContainer = co; httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"; httpWebRequest.Method = "GET"; webResponse = (HttpWebResponse)httpWebRequest.GetResponse(); header = webResponse.Headers.ToString(); getStream = webResponse.GetResponseStream(); streamReader = new StreamReader(getStream, Encoding.UTF8); getString = streamReader.ReadToEnd(); streamReader.Close(); getStream.Close(); return getString; }