日期:2014-05-18 浏览次数:20968 次
private static string getContent(string Url) { string content = ""; try { HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(Url); wreq.MaximumAutomaticRedirections = 4; wreq.MaximumResponseHeadersLength = 4; //wreq.Credentials = System.Net.CredentialCache.DefaultCredentials; //wreq.Referer = "http://www.macys.com"; //wreq.Headers.Add(HttpRequestHeader.Cookie, "macys_online=4416704358; shippingCountry=US; currency=USD;"); wreq.Method = "Get"; wreq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; wreq.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30"; CookieContainer cookieCon = new CookieContainer(); //CookieCollection cc = new CookieCollection(); //cc.Add(new System.Net.Cookie("currency", "USD", "/", "macys.com")); //cc.Add(new System.Net.Cookie("PPP", "24", "/", "macys.com")); //cc.Add(new System.Net.Cookie("SignedIn", "0", "/", "macys.com")); //cc.Add(new System.Net.Cookie("shippingCountry", "US", "/", "macys.com")); //cookieCon.Add(cc); wreq.CookieContainer = cookieCon; HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse(); StreamReader sr = new StreamReader(wresp.GetResponseStream()); content = sr.ReadToEnd(); } catch (Exception ex) { content = ex.Message; } return content; }