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

转载于:https://www.cnblogs.com/leeairw/archive/2011/03/05/1971840.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值