Метод отлично работает в Украине, но абсолютно не хочет срабатывать в США. Опять же в Украине работает с любыми прокси, в США прокси только добавляют 403 ошибку, даже при добавлении request.Credentials.
В США дэбаг выполнить, естественно не могу. Пишите пожалуйста любые догадки, по поводу того где искать проблему
В США дэбаг выполнить, естественно не могу. Пишите пожалуйста любые догадки, по поводу того где искать проблему
Код:
private HtmlDocument GetHtmlDocument(string urlForRequest)
{
lock (m)
{
try
{
WebRequest request = WebRequest.Create(urlForRequest);
int NumberOfRetries = 3;
for (int i = 1; i <= NumberOfRetries; ++i)
{
try
{
Stream objStream = request.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
HtmlDocument html = new HtmlDocument();
string temp = null;
temp = objReader.ReadToEnd();
if (temp != "" && temp != null)
{
html.LoadHtml(temp);
}
return html;
}
catch (Exception e)
{
// DO BETTER THAN THIS! Catch what you want to handle,
// not all exceptions worth a retry. Documentation and many
// tests will help you to narrow a limited subset of
// exceptions and error codes.
// Last one, (re)throw exception and exit
if (i == NumberOfRetries)
throw;
// Many network related errors will recover "automatically"
// after some time, exact delay is pretty arbitrary and
// should be determined with some tests. 1 second is pretty
// "good" for local I/O operations but network issues may
// need longer delays.
Thread.Sleep(1000);
}
}
return null;
}
catch(Exception ex)
{
AddLog("GetHtmlDocument", ex.Message);
return null;
}
}
}