Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC
Article

HTTP header and source extraction tool

Rate me:
Please Sign up or sign in to vote.
4.09/5 (8 votes)
14 Jul 20032 min read 98.6K   2.8K   33   22
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


Written By
Web Developer
United States United States
My real name is Sam I live in Monterey, California. I am currently unemployed - long story. I am trying to secure a job as a programmer in the Silicon Valley area of CA but so far no luck. Now with all this extra time I am writing code and learning concepts I have put off because I was too busy working Smile | :)

I have completed two of my programming goals: release software in the form of freeware, and write an article for CodeProject!

Comments and Discussions

 
Generalthank you very much! it's the thing I need. Pin
lb10-Apr-08 17:12
lb10-Apr-08 17:12 
GeneralAdding specific page support Pin
jdutchak3-Aug-07 2:48
jdutchak3-Aug-07 2:48 
Generalit doesn't send any GET vars Pin
Locura66620-Jun-04 8:04
Locura66620-Jun-04 8:04 
GeneralRe: it doesn't send any GET vars Pin
Djibril29-Jun-05 5:16
professionalDjibril29-Jun-05 5:16 
GeneralMake it more useful Pin
stubwang11-Nov-03 11:20
stubwang11-Nov-03 11:20 
GeneralRe: Make it more useful Pin
Code4Food11-Nov-03 17:32
Code4Food11-Nov-03 17:32 
GeneralRe: Make it more useful Pin
kiran_chikhale_IVI4-Sep-07 4:56
kiran_chikhale_IVI4-Sep-07 4:56 
GeneralMaking it work with PROXY Pin
darthmaul21-Jul-03 23:26
darthmaul21-Jul-03 23:26 
GeneralRe: Making it work with PROXY Pin
Code4Food22-Jul-03 8:56
Code4Food22-Jul-03 8:56 
GeneralNice! Pin
Ravi Bhavnani15-Jul-03 5:22
professionalRavi Bhavnani15-Jul-03 5:22 
Nice job! Also see my Web Resource Provider[^] article.

/ravi

Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com

GeneralRe: Nice! Pin
Code4Food15-Jul-03 5:32
Code4Food15-Jul-03 5:32 
GeneralRe: Nice! Pin
Ravi Bhavnani15-Jul-03 5:41
professionalRavi Bhavnani15-Jul-03 5:41 
GeneralIf you are interested in writing a webserver... Pin
Code4Food14-Jul-03 20:15
Code4Food14-Jul-03 20:15 
GeneralRe: If you are interested in writing a webserver... Pin
Richard Day15-Jul-03 0:42
Richard Day15-Jul-03 0:42 
GeneralRe: If you are interested in writing a webserver... Pin
Code4Food15-Jul-03 5:14
Code4Food15-Jul-03 5:14 
GeneralRe: If you are interested in writing a webserver... Pin
Christoph Lederer15-Jul-03 5:36
Christoph Lederer15-Jul-03 5:36 
GeneralRe: If you are interested in writing a webserver... Pin
Code4Food15-Jul-03 6:40
Code4Food15-Jul-03 6:40 
GeneralRe: If you are interested in writing a webserver... Pin
Hugo Hallman15-Jul-03 2:10
Hugo Hallman15-Jul-03 2:10 
GeneralRe: If you are interested in writing a webserver... Pin
Code4Food15-Jul-03 5:19
Code4Food15-Jul-03 5:19 
GeneralServer code and client code Pin
ETA16-Jul-03 20:47
ETA16-Jul-03 20:47 
GeneralRe: Server code and client code Pin
Code4Food17-Jul-03 5:15
Code4Food17-Jul-03 5:15 
GeneralRe: If you are interested in writing a webserver... Pin
Marcus Carey31-Jan-05 10:48
Marcus Carey31-Jan-05 10:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.