Hi,

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

Dani AI

Generated

For : two different problems need two different solutions. If the wiki uses HTTP authentication (Basic/Digest) you can fetch the page directly; if it uses a web form (most wikis) you must emulate the browser: POST the login form, preserve cookies, handle any CSRF token, then request the protected page.

Command-line quick paths (useful while prototyping)

  • HTTP auth (visible on process list — not recommended for production):
    curl --user 'USERNAME:PASSWORD' -L 'https://wiki.company/wiki/Page' -o page.html

    or

    wget --user=USERNAME --password=PASSWORD 'https://wiki.company/wiki/Page' -O page.html
  • Form login (two-step: POST credentials, save cookies, then GET page):
    curl -c cookies.txt -d 'username=USER&password=PASS' 'https://wiki.company/login' -L -s -o /dev/null
    curl -b cookies.txt -L 'https://wiki.company/wiki/Page' -o page.html

If you want a proper C++ solution, use libcurl (stable, widely used). The common pattern is: fetch login page (to get hidden token if required), submit credentials with cookie handling, then fetch the target page and write the response into a string or file. Minimal libcurl skeleton (captures body into a std::string and supports user:pass):

#include <curl/curl.h>
// write callback appends to std::string; set CURLOPT_USERPWD with "user:pass"
size_t write_cb(void* p, size_t s, size_t n, void* userdata) {
  ((std::string*)userdata)->append((char*)p, s*n);
  return s*n;
}

Use curl_easy_setopt for CURLOPT_URL, CURLOPT_WRITEFUNCTION, CURLOPT_WRITEDATA, CURLOPT_USERPWD (or handle POST + cookies for form logins), and CURLOPT_FOLLOWLOCATION.

Notes and troubleshooting

  • Inspect the login form in your browser (field names, action URL, hidden CSRF token) before scripting. Many wikis require the token on login.
  • Avoid embedding passwords on the command line (visible in ps). Prefer .netrc, prompting the user, or reading from a protected file.
  • Do not disable TLS verification in production.
  • If you prefer higher-level tooling, ’s note about WWW::Mechanize is valid for Perl; ’s pipe idea (popen) is handy for quick scripts; and when reading files in C++ prefer the idiom while (std::getline(...)) rather than testing eof, as and others discussed.

Recommended Answers

All 3 Replies

Look into pipes in *nix systems.

Also, if you are familiar with Perl you can use the WWW::Mehcanize or the Firefox::WWW::Mechanize library which is specifically suited to working with webpages. If a perl solution is acceptable I could give a few pointers.
-FH

Actually, your code should be:

while (file.good() && !file.eof())
{
    char buffer[MAX_LINE_SIZE + 1];
    file.getline(buffer, MAX_LINE_SIZE);
}

The signature for getline is this:

istream& getline (char* s, streamsize n );

There may be other issues, but this stood out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.