"Programming Environment" Visual Studio, NET4.0
"Development language" C #, in theory vb.net and other languages dependent on the. NET framework framework are affected by this
"Problem description"
Crawl Web content using HttpWebRequest, but the first request is always inexplicably blocked in request.getresponse (); But once the request succeeds, the subsequent operations are quick (if it's for the same object).
The same code is compiled in the NET3.5 environment but everything is OK, and in the NET4.0 environment to execute this problem, is it a bug?
"Solutions"
Add a configuration section in the configuration file (. config):
[HTML]View Plaincopyprint?
- <? XML version="1.0"?>
- <configuration>
- <startup>
- <supportedruntime version="v4.0" sku= ". netframework,version=v4.0 "/>
- </startup>
- <system.net>
- <defaultproxy
- enabled="false"
- usedefaultcredentials="false" >
- <proxy/>
- <bypasslist/>
- <module/>
- </defaultproxy>
- </system.net>
- </configuration>
"The problem Lies"
. The default proxy in NET4.0 is on, and I'm not setting it! It is blocked by waiting for the timeout to bypass the proxy.
Resources
"It's not a set at any 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 is consistent with my observations.
"
Http://msdn2.microsoft.com/en-us/library/kd3cf2ex (vs.80). aspx
"Problem extension"
If in another version of the. NET environment, you may want to try webclient.proxy = null, or httpwebrequest.proxy = null.
Summary
The problem is often out of focus, we need to be more ' careful '.
Hope to help you!
http://blog.csdn.net/rrrfff/article/details/6170653
[Fix WebClient or HttpWebRequest first-time connection problem]