HttpWebRequest's getrespons occasional timeout and death reasons and solutions

Source: Internet
Author: User
Tags garbage collection

At the time of making an interface, part of the requirements according to the user-specified URL, through the post way to send data, the previous debugging, has always been able to send data to get the return value, but then several debugging, in the absence of changes in the code, the result of the GetResponse will always die out.

After the internet Baidu has found the following several reasons and corresponding solutions:

1, modify the DefaultConnectionLimit to a larger value (the system defaults to 2)

System.Net.ServicePointManager.DefaultConnectionLimit = 50;

2. Add a garbage collection before HttpWebRequest req = (HttpWebRequest) webrequest.create (V_strurl)

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/

System.GC.Collect ();

3, after each use of HttpWebRequest to close the corresponding HTTP connection

Req. Close ();

Req=null;

The best corresponding HttpWebResponse also want close:

Rep. Close ();

Rep = null;

Detailed code case: Click to open the link

More detailed delay analysis: Click on the Open link

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.