链接检查器与 ShellExecute?
我的任务是每周检查数据库并检查所有链接。 我通常使用 PHP 工作,但在 PHP 中执行此操作会非常慢(实际上会在大约 100 个 URL 后使页面超时),因此我决定制作一个快速的 C++ 应用程序。
不可否认,自从大学以来我就没有使用过C++,所以我有点生疏了。
我找到了 ShellExecute 函数,并且它打开页面没有问题。 这是我到目前为止所得到的:
#include <shlobj.h>
#include <iostream>
using namespace std;
int main()
{
if( ShellExecute(NULL,"find","http://example.com/fdafdafda.php",NULL,NULL,SW_SHOWDEFAULT) )
{
cout << "Yes";
} else {
cout << "No";
}
cout << endl;
system("PAUSE");
return 0;
}
问题是它总是返回 true,无论它是否打开一个有效的页面。 它似乎正在检查关联的应用程序(在本例中为浏览器)是否能够毫无问题地打开文档,然后返回 true。 它不会查看浏览器是否收到 404 错误,它只是查看浏览器打开并运行,一切正常。
有一个更好的方法吗? 我是不是少了一步?
顺便说一句,我尝试使用 cURLcpp 的东西,但似乎无法弄清楚。 所有示例都指向下载中不存在的头文件。 我感觉 cURLcpp 是执行此操作的更好方法。
谢谢你的帮助。
I've been tasked with going through a database and checking all of the links, on a weekly schedule. I normally work in PHP, but doing this in PHP would be very slow (it actually would timeout the page after about 100 URLs), so I decided to make a quick C++ app.
Admitidly, I haven't used C++ since college, so I'm a bit rusty.
I found the ShellExecute function, and that it would open the page no problem. Here is what I have so far:
#include <shlobj.h>
#include <iostream>
using namespace std;
int main()
{
if( ShellExecute(NULL,"find","http://example.com/fdafdafda.php",NULL,NULL,SW_SHOWDEFAULT) )
{
cout << "Yes";
} else {
cout << "No";
}
cout << endl;
system("PAUSE");
return 0;
}
The problem is that it always returns true, whether it is opening a valid page or not. It appears to be checking if the associated app (a browser in this case) is able to open the document with no problems, then returns true. It isn't looking to see if the browser is getting a 404 or not, it simply sees it open and run and is fine.
Is there a better way to do this? Am I missing a step?
As an aside, I have attempted to use the cURLcpp stuff, but can't seem to figure it out. All of the examples point to header files that don't exist in the download. I have a feeling cURLcpp is the better way to do this.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你回答了你自己的问题。 ShellExecute 确实不适合这项任务,像 CURL 这样的东西会更好。
I think you answered your own question. ShellExecute is really not appropriate for this task, and something like CURL would be better.
或者,如果您不想使用外部库,您可以直接使用 InternetOpen、InternetOpenURL 等进行检查。
or if you don't want to use an external library you can check directly with InternetOpen, InternetOpenURL etc.
有关 ShellExecute 返回值的文档:
请参阅 ShellExecute 文档。
是的,CURL 会更好。
Documentation on the return value of ShellExecute :
See ShellExecute documentation.
And yes, CURL would be better.