system.net default proxy c# .Net 4

2019-07-25 17:28发布

问题:

I have some c# code (.Net 4) that makes calls to the Internet to get an XML file, however there is a long delay the first time the code block is hit! by adding the below to the app.conf the problem is resolved. However what I would like to do is check if there is a proxy uesd/set and if not then in code before each call turn off the proxy or the detection that is causing the 20 sec delay!

Can this be done? if so how would I do it?

<system.net> 
  <defaultProxy 
    enabled="false" 
    useDefaultCredentials="false" > 
    <proxy/> 
    <bypasslist/> 
    <module/> 
  </defaultProxy> 
</system.net> 

回答1:

WebRequest.DefaultWebProxy = new WebProxy();

Adding the above before the call seems to remove the delay.



回答2:

You may want to try something like this?

  <system.net>
    <defaultProxy enabled ="false">
      <proxy 
          autoDetect ="True"/>
    </defaultProxy>
  </system.net>


标签: c# proxy