检查网络服务器响应
我正在网站上制作这个文件夹扫描仪, 但在 2 个成功的网址之后,它会崩溃,我不知道为什么。
if (File.Exists(filePath))
{
StreamReader file = null;
file = new StreamReader(filePath);
while ((line = file.ReadLine()) != null)
{
var url = new Uri(txtUrl.Text + line);
try
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = true;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Win32)";
var response = (HttpWebResponse)request.GetResponse();
//Directory.ListView.Items.Add(url.ToString());
MessageBox.Show(url.ToString() + "Success");
}
catch (Exception err)
{
MessageBox.Show(url.ToString() + " fail: " + err.Message);
}
}
if (file != null)
file.Close();
MessageBox.Show("done;");
}
I'm making this folder scanner on a website,
but after 2 successful urls it will crash and i got no idea why.
if (File.Exists(filePath))
{
StreamReader file = null;
file = new StreamReader(filePath);
while ((line = file.ReadLine()) != null)
{
var url = new Uri(txtUrl.Text + line);
try
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = true;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Win32)";
var response = (HttpWebResponse)request.GetResponse();
//Directory.ListView.Items.Add(url.ToString());
MessageBox.Show(url.ToString() + "Success");
}
catch (Exception err)
{
MessageBox.Show(url.ToString() + " fail: " + err.Message);
}
}
if (file != null)
file.Close();
MessageBox.Show("done;");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要关闭 HTTPWebResponse 对象,
You need to close your HTTPWebResponse object,