简体   繁体   中英

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.

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.

scheme://username:password@host/path

From 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.

The best way, perhaps, depending on your needs, is the Boost based cpp.netlib.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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