繁体   English   中英

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

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

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

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

问题是,我想不出一个好的方法来做到这一点。 我使用的是 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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM