system.net 默认代理 c# .Net 4 [英] system.net default proxy c# .Net 4

查看:71
本文介绍了system.net 默认代理 c# .Net 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 c# 代码 (.Net 4) 可以调用 Internet 来获取 XML 文件,但是第一次命中代码块时会有很长的延迟!通过将以下内容添加到 app.conf 中,问题得到解决.但是,我想做的是检查是否有代理 uesd/set,如果没有,则在每次调用之前在代码中关闭代理或导致 20 秒延迟的检测!

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> 

推荐答案

WebRequest.DefaultWebProxy = new WebProxy();

在调用之前添加上述内容似乎可以消除延迟.

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

这篇关于system.net 默认代理 c# .Net 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆