Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6662981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:26:57+00:00 2026-05-26T02:26:57+00:00

I’m trying to download a file from a url. I try two approachs but

  • 0

I’m trying to download a file from a url. I try two approachs but it isn’t working with external files.

I think it’s happening because I have internet over proxy. I can download internal network files (images, mp3, mp4, whatever…) but when I try to download something in external network it gives me timeout or 404 Not Found.

1st approach: System.Net.WebResponse, System.IO.FileStream

     try
        {
            var credentials = new NetworkCredential("myNetworkUserName", "myNetworkPassword", "myNetworkDomain");
            var proxy = WebProxy.GetDefaultProxy(); //new WebProxy("myNetworkProxy") <-- I TRY BOOTH WAYS
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://farm1.static.flickr.com/83/263570357_e1b9792c7a.jpg"); //External image link

            proxy.Credentials = credentials;

            request.Proxy = proxy;

            responseExternalImage = request.GetResponse();//explode here ex=""Unable to connect to the remote server""

            string fileName = GetFileName(response.ResponseUri.OriginalString);
                Stream stream = response.GetResponseStream();

                using (BinaryReader br = new BinaryReader(stream))
                {
                    content = br.ReadBytes(50000000);//perto de 50Mb
                    br.Close();
                }
                response.Close();

                FileStream fs = new FileStream(pathToSaveFile + "\\" + fileName, FileMode.Create);
                BinaryWriter bw = new BinaryWriter(fs);
                try
                {
                    bw.Write(content);
                }
                finally
                {
                    fs.Close();
                    bw.Close();
                }
        }
        catch (Exception ex)
        {

        }

The exception caught at GetResponse() says: “Unable to connect to the remote server”, “”A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 77.238.160.184:80″”


2nd approach: System.Net.WebClient, DownloadFile

      try
        {
            var credentials = new NetworkCredential("xpta264", ConfigurationManager.AppSettings["Xpta264Password"], "ptsi");
            var proxy = WebProxy.GetDefaultProxy();
            proxy.Credentials = credentials;

            // Create a new WebClient instance.
            using (WebClient myWebClient = new WebClient())
            {
                myWebClient.Proxy = proxy;
                // Download the Web resource and save it into the current filesystem folder.
                myWebClient.DownloadFile("http://farm1.static.flickr.com/83/263570357_e1b9792c7a.jpg", pathToSaveFile + "\\testImage.jpg");
            }
        }
        catch (Exception e)
        {

        }

The exception was caught at DownloadFile method and gives me the same error.

Hope someone can help me.

Sorry for my English

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:26:58+00:00Added an answer on May 26, 2026 at 2:26 am

    WebProxy.GetDefaultProxy() is obsolete and doesn’t handle all cases. From the docs:

    Note: This API is now obsolete.

    The GetDefaultProxy method does not pick up any dynamic settings that
    are generated from scripts run by Internet Explorer, from automatic
    configuration entries, or from DHCP or DNS lookups.

    Applications should use the WebRequest.DefaultWebProxy property and
    the WebRequest.GetSystemWebProxy method instead of the GetDefaultProxy
    method.

    A better approach is to try to request a url and see if a proxy was used. I use this code in my own production system and it seems to work pretty well. Once you find the proxy, you can cache the address somewhere:

    WebProxy proxy = null;
    
    Uri testUri = new Uri("http://www.example.com/"); // replace with REAL url
    Uri proxyEndpoint = WebRequest.GetSystemWebProxy().GetProxy(testUri);
    if (!testUri.Equals(proxyEndpoint))
        proxy = new WebProxy(proxyEndPoint.ToString());
    

    You can also just try calling WebRequest.GetSystemWebProxy() and see if that gives you the proxy, but I remember having problems with that which is why I went the request route above. YMMV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.