简体   繁体   English

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

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

First of all, i am not trying to hack into anything or anyones e mails.首先,我并不是要侵入任何东西或任何人的电子邮件。

I am new software engineer and I need to log into company wiki page & download info displayed into a text file or something, so i can search for data i am looking for and make dessions based on what i learned from the wiki page.我是新的软件工程师,我需要登录到公司维基页面并将显示的信息下载到文本文件或其他内容中,这样我就可以搜索我正在寻找的数据并根据我从维基页面中学到的知识进行讨论。 I do have a user name and password for the wiki page and no need for breaking in.我确实有维基页面的用户名和密码,不需要闯入。

Issue is, I can not figure out a good way to do this.问题是,我想不出一个好的方法来做到这一点。 I am using C++ and operating system is Linux.我使用的是 C++,操作系统是 Linux。

Here is what I have so far.这是我到目前为止所拥有的。 This does not issue the uer name and password.这不会发出用户名和密码。 Can someone please tell me how to issue usename and password?有人可以告诉我如何发出用户名和密码吗?

 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();

Same way as with any URL.与任何 URL 相同。

scheme://username:password@host/path

From TFM :来自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);

The simplest way, IMHO, is to use curl. Curl is a more sophisticated web client than wget.恕我直言,最简单的方法是使用 curl。Curl 是比 wget 更复杂的 web 客户端。

The best way, perhaps, depending on your needs, is the Boost based cpp.netlib.根据您的需要,最好的方法也许是基于 Boost 的 cpp.netlib。

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

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