I write an application that acces to website and get html source, but after about 300 400 request, my httpwebrespond won't response and my application stuck.
Anyone know how to solved it ?
My code
HttpWebRequest RequestPage = (HttpWebRequest)WebRequest.Create("http://domain.com/somepage.html");
RequestPage.Timeout = 30000;
RequestPage.Method = "GET";
RequestPage.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
RequestPage.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36";
string HtmlSourcePage = "";
using (HttpWebResponse RespondPage = (HttpWebResponse)RequestPage.GetResponse())
{
StreamReader StreamReaderPage = new StreamReader(RespondPage.GetResponseStream(), System.Text.Encoding.UTF8);
HtmlSourcePage = StreamReaderPage.ReadToEnd();
StreamReaderPage.Dispose();
StreamReaderPage.Close();
StreamReaderPage = null;
}
RespondPage.Close(); RequestPage.Abort();
You need to set the maxconnection
of connectionManagement in app.config
/ web.config
file:
<configuration>
<system.net>
<connectionManagement>
<add address="*" maxconnection="500" />
</connectionManagement>
</system.net>
</configuration>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.