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] 阅读(55) 评论(0) 编辑 收藏

导航

<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

公告

立即注册PayPal并开始接受信用卡付款。
昵称:鬼蝶[DFCG]
园龄:6年11个月
粉丝:0
关注:0

搜索

 
 

常用链接

我的标签

随笔分类

随笔档案

友情链接

最新评论

阅读排行榜

评论排行榜

推荐排行榜