bool sucess = false;
var htmlDocument = new HtmlDocument();
while (!sucess)
{
try
{
var httpWebRequest = (HttpWebRequest) WebRequest.Create(aUrl);
httpWebRequest.CookieContainer = Cookies;
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1";
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.Pipelined = true;
httpWebRequest.KeepAlive = true;
httpWebRequest.ServicePoint.ConnectionLimit = 3000000;
httpWebRequest.Referer = aReferer;
httpWebRequest.Method = aMethod;
httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip;
httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
httpWebRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
if (aMethod == "POST")
{
using (var stream = httpWebRequest.GetRequestStream())
using (var sw = new StreamWriter(stream))
{
sw.Write(aParameter);
sw.Flush();
}
}
using (var response = (HttpWebResponse) httpWebRequest.GetResponse())
using (var stream = response.GetResponseStream())
{
htmlDocument.LoadHtml(new StreamReader(stream, Encoding.UTF8).ReadToEnd());
//htmlDocument.Load(stream, Encoding.UTF8);
}
sucess = true;
}
catch (Exception)
{
sucess = false;
}
}
Tell me more
×
Code Review Stack Exchange is a question and answer site for
peer programmer code reviews. It's 100% free, no registration required.
|
|||||
|