Resolve slow first connection WebClient or HttpWebRequest issues

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):

<?XML version= "1.0"?>  <Configuration>    <Startup>      <supportedruntimeversion= "v4.0"SKU=". netframework,version=v4.0 "/>    </Startup>    <System.Net>      <defaultproxyenabled= "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!

Resolve slow first connection WebClient or HttpWebRequest issues

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.