May 2019
Intermediate to advanced
478 pages
11h 21m
English
In addition to the 400 Bad Request error, our server also needs to handle the case where a requested resource is not found. In this case, a 404 Not Found error should be returned. We define a helper function to return this error as follows:
/*web_server.c except*/void send_404(struct client_info *client) { const char *c404 = "HTTP/1.1 404 Not Found\r\n" "Connection: close\r\n" "Content-Length: 9\r\n\r\nNot Found"; send(client->socket, c404, strlen(c404), 0); drop_client(client);}
The send_404() function works exactly like the send_400() function defined previously.
Read now
Unlock full access