Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

HTTP header and source extraction tool

0.00/5 (No votes)
14 Jul 2003 5  
Tool to retrieve the header and source file from a URL.

Sample Image - hextract.jpg

Introduction

I created this tool in order to help facilitate my new project of creating a web server using straight Winsock2 calls. After spending a couple of hours creating it, I realized I really did not need to have this tool. However, it has given me a better understanding of the headers returned from a 'GET' statement made to the website. For fun, try entering some popular website you know of and see if it returns anything you find odd. For example, typing in 'www.redhat.com' and having the Server line return "Microsoft/IIS".

Usage

Enter the URL in the top edit box and then hit the 'Get Data' button. This will get the default document in the URL you entered and the header information as seen by your browser, and what is returned by the server. This tool would be helpful for someone building a web browser, as opposed to a web server, but it does give you a good view of the header information returned. The source file is the same as you would get from using Internet Explorer and going to "view source".

Credit

  • MSDN
  • CodeProject people from this thread, who helped me sort out my \r\n problems

Oddities

I initially tried to use the CHttpFile.Read() member function but it only wanted to read in 4KB of data. I tried setting the buffer but could not get it to read in all the data to display in the HTML source box. I had to use the ReadString() function instead and keep appending it to another data CString. If anyone can elaborate on this for me, I would be much appreciative.

Future

At this time I do not have any plans for this code just because I realized I really did not need it to write a web server. If you have any suggestions on how to upgrade the code, for a tool you would use, please let me know, as I am open to any suggestions.

History

  • 07/14/2003 - Released article and code (version 1.0)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here