954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

http request parse

httpRequest parseHttpRqt(char *msg) {
	httpRequest rtrn;
	
	
	return rtrn;
}


I was just wondering if anybody could help with parsing a Http Request? I understand that the request is as illustrated below, but how would i turn that into an object containing the code (200/400/404) and the filename? Bearing in mind that I am only concerned with GET requests.

GET /index.html HTTP/1.1\r\n
host: somewebsite.com\r\n
\r\n
purpleturtle_97
Newbie Poster
3 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

In real world you would simply use a library.

wingless
Newbie Poster
15 posts since Oct 2009
Reputation Points: 10
Solved Threads: 2
 

The HTTP format is very well specified ( see here ). You can simply pull apart the fields you need and ignore the ones you do not.

That aside, I think that wingless provides the best advice: use existing software.

L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124
 

Thanks for the replies but I really want to do this without using a 3rd party library.

purpleturtle_97
Newbie Poster
3 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

If the data is in a file,I'd use fgets() to get each row, then strstr() to look for GET in any row, and sscanf() to save it into the variable that you want.

Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: