Simple HTTP Server in C - How to Respond to a Browser?

my server sends a sample response with the body to the request:

static char* not_found_response_template = "HTTP/1.1 404 Not Found\n" "Content-type: text/html\n" "\n" "<html>\n" " <body>\n" " <h1>Not Found</h1>\n" " <p>The requested URL was not found on this server.</p>\n" " </body>\n" "</html>\n"; len = strlen(not_found_response_template); send(newSct, not_found_response_template, len, 0); 

it sends it correctly, but firefox continues to load until I cancel the transfer.

the firefox plugin HttpRequestHelper shows this:

GET localhost: 6666

- answer - 404 Not found Content-Type: text / html

Why is the content not uploaded?

+4
source share
2 answers

Try flushing and / or closing the socket after sending the response.

+2
source

HTTP requires lines to be terminated by CR + LF, so try \r\n .

+5
source

All Articles