こんにちは、Web アプリケーション内に単純なスレッドプール ベースの Web クローラーを作成しました。その仕事は、独自のアプリケーション スペースをクロールし、すべての有効な Web ページとそのメタ コンテンツの Lucene インデックスを構築することです。これが問題です。Visual Studio Express のデバッグ サーバー インスタンスからクローラーを実行し、開始インスタンスを IIS URL として指定すると、正常に動作します。ただし、IIS インスタンスを提供せず、独自の URL を使用してクロール プロセスを開始すると (つまり、独自のドメイン スペースをクロールする)、Webresponse ステートメントで操作タイムアウト例外が発生します。誰かが私がここですべきこと、すべきでないことを教えてくれませんか? これがページを取得するための私のコードです。マルチスレッド環境で実行されます。
private static string GetWebText(string url)
{
string htmlText = "";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.UserAgent = "My Crawler";
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
htmlText = reader.ReadToEnd();
}
}
}
return htmlText;
}
そして、以下は私のスタックトレースです:
at System.Net.HttpWebRequest.GetResponse()
at CSharpCrawler.Crawler.GetWebText(String url) in c:\myAppDev\myApp\site\App_Code\CrawlerLibs\Crawler.cs:line 366
at CSharpCrawler.Crawler.CrawlPage(String url, List`1 threadCityList) in c:\myAppDev\myApp\site\App_Code\CrawlerLibs\Crawler.cs:line 105
at CSharpCrawler.Crawler.CrawlSiteBuildIndex(String hostUrl, String urlToBeginSearchFrom, List`1 threadCityList) in c:\myAppDev\myApp\site\App_Code\CrawlerLibs\Crawler.cs:line 89
at crawler_Default.threadedCrawlSiteBuildIndex(Object threadedCrawlerObj) in c:\myAppDev\myApp\site\crawler\Default.aspx.cs:line 108
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
ありがとう、レオン。