日期:2014-05-17 浏览次数:20362 次
/// <summary>
/// 通过get方式请求页面,传递一个实例化的cookieContainer
/// </summary>
/// <param name="postUrl"></param>
/// <param name="cookie"></param>
/// <returns></returns>
public static ArrayList GetHtmlData(string postUrl, CookieContainer cookie)
{
HttpWebRequest request;
HttpWebResponse response;
ArrayList list = new ArrayList();
request = WebRequest.Create(postUrl) as HttpWebRequest;
request.Method = "GET";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; CIBA; .NET4.0C; .NET4.0E)";
request.CookieContainer = cookie;
request.KeepAlive = true;
request.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
try
{
//获取服务器返回的资源
using (response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default))
{
if (response.Cookies.Count > 0)