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

Recommended Answers

All 4 Replies

In real world you would simply use a library.

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.