首页 > 解决方案 > 使用 unix 下载 html 文件

问题描述

我想使用 c++ 下载一个 html 文件。我有一些适用于 Visual Studio 的代码,但我需要它在 unix 中运行并能够使用 gcc 进行编译。我发现很多与此类似的问题都有很好的答案,但在 unix 中没有任何效果。这是我在视觉工作室中完美运行的代码......

#include <urlmon.h>
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    char webAddress[256] = "https://www.ibm.com/us-en/?ar=1";
    char szFileName[80] = "ibm.html";



    HRESULT hr = URLDownloadToFile(NULL, webAddress, szFileName,0, NULL);

    if (hr == S_OK)
    {
        ifstream fin(szFileName);
        char szBuff[2048];

    }
    else
    {
        cout << "Operation failed with error code: " << hr << "\n";
    }

    return 0;
}

标签: c++httpunixgcc

解决方案


您可能喜欢使用libCURL,这几乎就是您所描述的。

这里有一些示例应用程序,特别是演示了使用方法是多么简单。

参考


推荐阅读