[Fix WebClient or HttpWebRequest first-time connection problem]

Source: Internet
Author: User

"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?
  1. <? XML version="1.0"?>
  2. <configuration>
  3. <startup>
  4. <supportedruntime version="v4.0" sku= ". netframework,version=v4.0 "/>
  5. </startup>
  6. <system.net>
  7. <defaultproxy
  8. enabled="false"
  9. usedefaultcredentials="false" >
  10. <proxy/>
  11. <bypasslist/>
  12. <module/>
  13. </defaultproxy>
  14. </system.net>
  15. </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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.