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

  • Home
  • SEARCH
  • 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 957213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:39:59+00:00 2026-05-16T00:39:59+00:00

Another question about Web proxy. Here is my code: IWebProxy Proxya = System.Net.WebRequest.GetSystemWebProxy(); Proxya.Credentials

  • 0

Another question about Web proxy.

Here is my code:

IWebProxy Proxya = System.Net.WebRequest.GetSystemWebProxy();
Proxya.Credentials = CredentialCache.DefaultNetworkCredentials;
HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create(targetServer);

rqst.Proxy = Proxya;
rqst.Timeout = 5000;
try
{
    rqst.GetResponse();
}
catch(WebException wex)
{
    connectErrMsg = wex.Message;
    proxyworks = false; 
}

This code hangs the first time it is called for a minute of two. After that on successive calls it works sometimes, but not others. It also never hits the catch block.

Now the weird part. If I add a MessageBox.Show(msg) call in the first section of code before the GetResponse() call this all will work every time without hanging. Here is an example:

try
{
    // ========Here is where I make the call and get the response========
    System.Windows.Forms.MessageBox.Show("Getting Response");
    // ========This makes the whole thing work every time========


    rqst.GetResponse();
}
catch(WebException wex)
{
    connectErrMsg = wex.Message;
    proxyworks = false; 
}

I’m baffled about why it is behaving this way. I don’t know if the timeout is not working (it’s in milliseconds, not seconds, so should timeout after 5 seconds, right?…) or what is going on. The most confusing this is that the message box call makes it all work without hanging.

So any help and suggestions on what is happening is appreciated. These are the kind of bugs that drive me absolutely out of my mind.

EDIT and CORRECTION:

OK, so I’ve been testing this and the problem is caused when I try to download data from the URI that I am getting a response from. I am testing the connectivity using the GetResponse() method with a WebRequest, but am downloading the data with a WebClient. Here is the code for that:

public void LoadUpdateDataFromNet(string url, IWebProxy wProxy)
{
    //Create web client
    System.Net.WebClient webClnt = new System.Net.WebClient();

    //set the proxy settings
    webClnt.Proxy = wProxy;
    webClnt.Credentials = wProxy.Credentials;

    byte[] tempBytes;
    //download the data and put it into a stream for reading
    try
    {
        tempBytes = webClnt.DownloadData(url); // <--HERE IS WHERE IT HANGS
    }
    catch (WebException wex)
    {
        MessageBox.Show("NEW ERROR: " + wex.Message);
        return;
    }

    //Code here that uses the downloaded data
}

The WebRequest and WebClient are both accessing the same URL which is a web path to an XML file and the proxy is the same one created in the method at the top of this post. I am testing to see if the created IWebProxy is valid for the specified path and file and then downloading the file.

The first piece of code I put above and this code using the WebClient are in separate classes and are called at different times, yet using a message box in the first bit of code still makes the whole thing run fine, which confuses me. Not sure what all is happening here or why message boxes and running/debugging in Visual Studio makes the program run OK. Suggestions?

  • 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-16T00:40:00+00:00Added an answer on May 16, 2026 at 12:40 am

    So, I figured out the answer to the problem. The timeout for the we request is still 5 sec, but for some reason if it is not closed explicitly it makes consecutive web requests hang. Here is the code now:

    IWebProxy Proxya = System.Net.WebRequest.GetSystemWebProxy();
    
    //to get default proxy settings
    Proxya.Credentials = CredentialCache.DefaultNetworkCredentials;
    Uri targetserver = new Uri(targetAddress);
    Uri proxyserver = Proxya.GetProxy(targetserver);
    
    HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create(targetserver);
    rqst.Proxy = Proxya;
    rqst.Timeout = 5000;
    
    try
    {
        //Get response to check for valid proxy and then close it
        WebResponse wResp = rqst.GetResponse();
    
        //===================================================================
        wResp.Close(); //HERE WAS THE PROBLEM. ADDING THIS CALL MAKES IT WORK
        //===================================================================
    }
    catch(WebException wex)
    {
        connectErrMsg = wex.Message;
        proxyworks = false; 
    }
    

    Still not sure exactly how calling the message box was making everything work, but it doesn’t really matter at this point. The whole thing works like a charm.

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

Sidebar

Ask A Question

Stats

  • Questions 481k
  • Answers 481k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What problems will you have? Well, if everything compiles, then… May 16, 2026 at 6:26 am
  • Editorial Team
    Editorial Team added an answer I think your problem is this line: content = file['content']… May 16, 2026 at 6:26 am
  • Editorial Team
    Editorial Team added an answer Are you using any IDE or compiling the program at… May 16, 2026 at 6:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.