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

Compiling the program

As you recall I said this program depends upon the Winsock API/library. So in order to compile the project we will have to link it against ws2_32.a. In order to do that click Project > Project Options on the menu. Then click the "Parameters" tab. Then click the button entitled "Add library or Object" and navigate to your DevC++ lib directory. I installed Dev C++ in C:\ so for me the path to the lib directory is C:\Dev-Cpp\lib. Inside the lib directory select the file named "ws2_32.a" and click the Open button. The Linker section of the Parameter tab should be filled with a file path to the ws2_32.a file. Click on the OK button. At this point the project is ready to be compiled. Go to Execute > Compile & Run on the menu or click on the compile button on the toolbar.

By the way, if you run my project on your computer you will also need to perform this procedure before the IDE will let you compile the program. Otherwise the IDE will show you a linking error.

Conclusion

That is the complete program. Amazing how it seemed like such a simple program but it took a while to explain. At this point since the program itself has been written and it works, it would be a good time to go back and add optimizations such as inlining the BasicWebpage's accessor methods. I sincerely hope you learned something and enjoyed this article. Good luck on your future projects!

<< Previous