[英]HttpWebRequest, HttpWebResponse stuck after a lot of request
我編寫了一個訪問網站並獲取html源的應用程序,但是在請求300400之后,我的httpwebrespond無法響應,並且應用程序卡住了。
有人知道如何解決嗎?
我的密碼
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();
您需要設置maxconnection
connectionManagement中app.config
/ web.config
的文件:
<configuration>
<system.net>
<connectionManagement>
<add address="*" maxconnection="500" />
</connectionManagement>
</system.net>
</configuration>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.