system.net default proxy c# .Net 4

2019-07-25 17:27发布

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> 

标签: c# proxy
2条回答
该账号已被封号
2楼-- · 2019-07-25 17:33
WebRequest.DefaultWebProxy = new WebProxy();

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

查看更多
在下西门庆
3楼-- · 2019-07-25 17:35

You may want to try something like this?

  <system.net>
    <defaultProxy enabled ="false">
      <proxy 
          autoDetect ="True"/>
    </defaultProxy>
  </system.net>
查看更多
登录 后发表回答