2012-04-10 37 views
0

首先,我不是想侵入任何东西或任何电子邮件。如何在Linux下使用C++下载受密码保护的URL?

我新的软件工程师,我需要登录到公司的wiki页面显示到一个文本文件或东西&下载信息,这样我就可以搜索的数据我找的,并根据我从维基了解到dessions页。我有一个维基页面的用户名和密码,不需要打入。

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

回答

2

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

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

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

+0

而且使用编程'libcurl'也是一个不错的主意... – 2012-04-10 19:43:25

0
#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); 
+0

主机我试图访问竟然是一类3安全服务器和不喜欢我在做什么。有没有解决的办法? – usustarr 2012-04-10 21:06:03

+0

将“--debug --verbose”添加到您的命令中,并发布您对原始问题的看法。 – 2012-04-10 21:10:19

相关问题