链接检查器与 ShellExecute?

发布于 2024-07-26 14:57:22 字数 866 浏览 6 评论 0原文

我的任务是每周检查数据库并检查所有链接。 我通常使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抚笙 2024-08-02 14:57:22

我想你回答了你自己的问题。 ShellExecute 确实不适合这项任务,像 CURL 这样的东西会更好。

I think you answered your own question. ShellExecute is really not appropriate for this task, and something like CURL would be better.

帅气尐潴 2024-08-02 14:57:22

或者,如果您不想使用外部库,您可以直接使用 InternetOpen、InternetOpenURL 等进行检查。

or if you don't want to use an external library you can check directly with InternetOpen, InternetOpenURL etc.

为你拒绝所有暧昧 2024-08-02 14:57:22

有关 ShellExecute 返回值的文档:

如果函数成功,则返回一个大于 32 的值。如果函数失败,则返回一个错误值,指示失败的原因。 返回值被转换为 HINSTANCE 以向后兼容 16 位 Windows 应用程序。 然而,这并不是真正的实例。 它只能转换为 int 并与 32 或下面的错误代码进行比较。

请参阅 ShellExecute 文档。

是的,CURL 会更好。

Documentation on the return value of ShellExecute :

If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.

See ShellExecute documentation.

And yes, CURL would be better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文