C webserver header sending
I wrote a simple web server in C that listens for a connection开发者_JAVA技巧 and send some text over a socket. I want my server to be accessed by a server. In this case I should s*end headers such as CODE(200), Content type, Content length*.
- How these headers can be sent to the client(browser or telnet)?
- How headers of request can be extracted?
(Maybe, I just don't understand the question, vote me down.)
The http response header format is not too difficult:
header1\n
header2\n
<empty line>\n
content\n
content\n
That's all. The webserver should send the headers, an empty line, then the content.
If you wanna test header sending, you should check it with a browser. Add a line to your webserver to send the following header:
Content-Disposition: attachment; filename=download_me.txt
So when you connect to your webserver with a browser, it will pop up a "save as" dialog instead of displaying the downloaded web page in the browser window. If you got the dialog, and the downloaded file is also OK, your webserver sends the headers properly.
G It's another issue, wether the client handles them as you (and W3C) expect...
Edit: HTTP ok status is:
HTTP/1.1 200 OK\n
Google for more status codes.
精彩评论