如何在 Linux 中使用C++下载受密码保护的 URL

How to download a password protected URL using C++ in Linux?

本文关键字:下载 密码保护 URL C++ Linux      更新时间:2023-10-16

首先,我不想入侵任何东西或任何人的电子邮件。

我是新的软件工程师,我需要登录公司维基页面并下载显示到文本文件或其他东西中的信息,这样我就可以搜索我正在寻找的数据,并根据我从维基页面学到的知识做出决定。我确实有维基页面的用户名和密码,不需要闯入。

问题是,我想不出一个好的方法。我正在使用C++操作系统是Linux。

这是我到目前为止所拥有的。这不会发出用户名和密码。有人可以告诉我如何发布用户名和密码吗?

string line;
system("wget www.cooperateweb.com/wikipage/productpage/FWversions+date");
ifstream file ("index.html");
while (!file.eof())
{
getline(file,line);
cout<<line<<"n";    }    file.close();

与任何URL相同。

scheme://username:password@host/path

来自全聚焦方式(TFM):

 --user=user
 --password=password
    Specify the username user and password password for both FTP and HTTP
    file retrieval. These parameters can be overridden using the --ftp-user
    and --ftp-password options for FTP connections and the --http-user and
    --http-password options for HTTP connections. 
#define MAX_CMD_LENGTH 1000;
char cmdBuffer[MAX_CMD_LENGTH];
/* for sake of demonstration */
char *username = "foo";
char *password = "bar";
sprintf(cmdBuffer, "wget --user=%s --password=%s http://www.cooperateweb.com/wikipage/productpage/FWversions+date", username, password);
char *cmd = malloc(strlen(cmdBuffer) + 1);
strncpy(cmd, cmdBuffer, strlen(cmdBuffer) + 1);
system((const char *)cmd);
free(cmd);

恕我直言,最简单的方法是使用 curl。 Curl是一个比wget更复杂的Web客户端。

根据您的需求,最好的方法可能是基于 Boost 的 cpp-netlib。