HttpWebRequest 首次连接缓慢问题

 NET Framework 4.0 中的HttpWebRequest默认使用代理访问,所以首次请求就变得超慢,每次到Request.GetResponse();这里都得卡上几十秒!不过一旦这次请求成功,后续的就快了(如果是同一网站)。这并不正常!以前使用NET2.0/3.5没有此类问题,相同的代码编译在NET4.0环境中执行就出这问题,难道是一个BUG?

经过搜索,终于发现了问题,原来.NET4.0中的默认代理是开启的。

"It's not set at all in app.cong or machine.config. Hmm. If I'm reading the 
MSDN docs right, the default for defaultProxy.enabled is TRUE if the element 
isn't specified at all. That would be consistent with my observations.
"

解决方法:

.config文件中添加配置节

 

<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false" >
<proxy usesystemdefaults="true" proxyaddress="http://192.168.1.10:3128/" bypassonlocal="true" />
<bypasslist>
      
<add address="[a-z]+\.contoso\.com" />
</bypasslist>
<module/>
</defaultProxy>
</system.net>

 

参考资料:

http://msdn2.microsoft.com/en-us/library/kd3cf2ex(VS.80).aspx

posted on 2011-03-05 21:33  鬼蝶[DFCG]  阅读(458)  评论(0编辑  收藏  举报

导航