Problems with reading HTTP requests

Hi all,

I am trying to implement a simple HTTP server with C that

1. reads a request
2. checks if it is a GET request
3. reads the URL from the request
4. Checks if file is on server and tries to open it
I am using strtok for String tokenizing and I think it messes up the filepath. open and fopen always return error codes and are not able to open any files.

Here is my code: http://pastebin.com/EWtSwLfH

So I'm placing a test.html in the same folder as the server. Then im telnetting to localhost and port 3499. This is the output when entering GET /test.html:
/test.html
test.html
test.htmlNot existed
Connection closed by foreign host.
Line 39. You're not initialising the socket with a protocol. It may work on your system, but it's not correct or portable.

Line 52. You haven't set the size in the call to memset, so it does nothing.

You're not adhering to the protocol as far as I can tell.
readline: You need to read until you read the end of stream sequence, which is \r\n\r\n.
And as for what you're returning ...

I think you should stop and read up on the RFC on the HTTP 1.0 protocol, it's reasonably short. Then get the RFC on HTTP 1.1 and check out what's added to the request header/reply.

The protocols are well established and documented. You just need to read them if you want to implement them.
i highly recommend you to use a 3rd party library like libcurl to handle HTTP requests for you, especially HTTP 1.1 ones which can be more complex then you think:
http://curl.haxx.se/libcurl/
Topic archived. No new replies allowed.