如何在VC中判断没有Web文件?
我试图用下面的程序来读取一个Web文件:
strFileName="http://www.fadshop.net/squirrel/test.htm";
CInternetSession sess;//建立会话
CHttpFile* fileGet;
CException* e;
TRY
{
fileGet=(CHttpFile*)sess.OpenURL(strFileName);//打开文件
}
CATCH_ALL(e)
{
fileGet = 0; //如果出错就设为0
}
END_CATCH_ALL
if(fileGet) //如果出错或无法打开就不望下执行。
{
CStdioFile fileWrite;
if(fileWrite.Open(strWriteName, CFile::modeWrite|CFile::modeCreate)){
while(fileGet->ReadString(strSentence)){
fileWrite.WriteString(strSentence+"\n");
}
fileWrite.Close();
}
fileGet->Close();
}
sess.Close();
------------
但是在
if(fileGet) //如果出错或无法打开就不望下执行。
不按照我所想像的执行,因为当文件存在时程序正常的运作
当文件不存在时也能fileGet也是非0,并且得到WriteFile的结果如下:
<html>
<head>
<title>错误 404</title>
<meta name="robots" content="noindex">
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb_2312">
</head>
<body>
<h2>HTTP 错误 404</h2>
<p><strong>404 找不到</strong></p>
<p>Web 服务器找不到您所请求的文件或脚本。请检查
URL 以确保路径正确。</p>
<p>如果问题依然存在,请与服务器的管理员联系。</p>
</body>
</html>
我应该如何让Web文件不存在时不执行读文件的操作呢?
就此祝好,松鼠拜上
http://www.fadshop.net/squirrel/