Programming an HTML Downloader in C++

Written By: Alwyn Malachi Berkeley

- 25 Sep 2006 -
















Description: This program requests the source code (HTML) of a webpage and then gives the user multiple options for viewing the web server's response. We will use the Winsock API to manipulate sockets on the system, and create reusable code along the way.

  1. Creating the Project
  2. main.cpp Headers and the Internet Namespace
  3. The Webpage Class
  4. The Internet Namespace's Functions
  5. GetDomain
  6. Custom_itoa
  7. GetWebpage
  8. SaveFile
  9. Internet.hpp and Writing main.cpp
  10. Compile and Conclusion

Defining the Internet namespace's four functions

Now, if you recall there are four other functions that are defined by the Internet namespace. The name of those four functions are GetDomain(), Custom_itoa, GetWebpage(), and SaveFile(). To define these functions go to File > New > Source File once again, and this time, fill it with the following code below:

#ifndef HELPER_FUNCTIONS_HPP
#define HELPER_FUNCTIONS_HPP
 
#include 
#include 
#include "BasicWebpage.hpp"
 
namespace Internet {
        const char* GetDomain(const std::string &strWebpageURLParam);
        
        const char* Custom_itoa(int intParam);
 
        std::auto_ptr GetWebpage(const std::string &strWebpageURLParam);
 
        const bool SaveFile(const std::string &strFileNameParam, const std::string &strSaveDataParam);
}
 
#endif 

Simple as that, we are done defining the four functions. Save the source file under the name "InternetHelperFunctions.hpp".

Now let us take a look at the function implementations. Note that I will skip past outlining what headers are needed and skip by explaining how to declare a namespace because that information is too trivial. You can take a gander at my source code for those minute details. For now let's press on to the meat and potatoes.

<< Previous

Next >>