. Net URL request page content unable to connect to the remote server

Source: Internet
Author: User
private static string DownloadFile(string fetchUrl, int requestTimeout, int requestRetryCount)        {            while (true)            {                try                {                    using (HttpWebResponse response = (HttpWebResponse)CreateWebRequest(fetchUrl, requestTimeout).GetResponse())                    {                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))                        {                            return reader.ReadToEnd();                        }                    }                }                catch                {                    if (requestRetryCount <= 0)                    {                        throw;                    }                    requestRetryCount--;                }            }        }
private static WebRequest CreateWebRequest(string fetchUrl, int requestTimeout)        {            HttpWebRequest.DefaultCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);            WebRequest request = WebRequest.Create(new Uri(fetchUrl));            request.Timeout = requestTimeout;            request.Method = "GET";            request.ContentType = "application/x-www-form-urlencoded";            request.Credentials = CredentialCache.DefaultCredentials;            request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);            request.Proxy = new WebProxy("sinproxy.southpacific.corp.microsoft.com");            return request;        }

Note:

If the error "unable to connect to the remote server" is reported and can be accessed through a browser, you must have missed this sentence, as shown below.

Request. Proxy = new WebProxy ("sinproxy.southpacific.corp.microsoft.com ");

To access the URL through a browser or your own code, make sure that the environment is the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.