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;
}
}
Take the 2-minute tour
×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.
|
||||
show 1 more comment |
closed as unclear what you're asking by Malachi, 200_success, rolfl, Mat's Mug, Nikita Brizhak Nov 15 '13 at 11:52
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.
aReferer
andaMethod
– Malachi Nov 14 '13 at 20:14