Quantcast
Channel: Форум программистов и сисадминов Киберфорум
Viewing all articles
Browse latest Browse all 517434

.NET 4.x WebRequest не срабатывает в другой стране - C# под Web, ASP.NET

$
0
0
Метод отлично работает в Украине, но абсолютно не хочет срабатывать в США. Опять же в Украине работает с любыми прокси, в США прокси только добавляют 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;
                }
            }
        }


Viewing all articles
Browse latest Browse all 517434

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>