Removing obsolete WebProxy.GetDefaultProxy() references

前端 未结 1 608
天命终不由人
天命终不由人 2021-01-20 17:36

I have a bit of code which is annoying me because it is generating obsolete warnings, but I am wary of removing it because:

a) It works

b) I didn\'t write it

相关标签:
1条回答
  • 2021-01-20 18:34

    Yes I think you are right.

    A good way to test this is with Fiddler because one of the things it does (apart from trace http requests) is to automatically set itself up as your IE proxy.

    If you run the Fiddler and then the following piece of code

     HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://news.bbc.co.uk");
     //request.Proxy = null; // uncomment this to bypass the default (IE) proxy settings
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
     Console.WriteLine("Done - press return");
     Console.ReadLine();
    

    you will see that with no explicit proxy override in the code (as in "what I really should do is just delete these four lines"), the request does indeed pick up the global default proxy from IE, and you will see your request in Fiddler.

    Only when you uncomment the null proxy assignment, does the request bypass the global proxy settings and not appear in Fiddler.

    So yes - I think you are right; for the default proxy you can remove the explicit proxy code.

    0 讨论(0)
提交回复
热议问题