I am sending HTTP GET request and receiving data here:
ssize_t numBytes = recvfrom(sock, request, 1000, 0,
(struct sockaddr *) &myaddr, &fromAddrLen);
if(numBytes < 0)
printf("The requested resource does not exist.\n");
else
printf("the webpage exist :)\n");
I want to check whether the requested page exist or not. But even if a page does not exist, status message is often sent from server (something like “404 not found”).
It is still some data, thus I cannot get numBytes<0.
How can I check the status of response to be able to verify the existence of the page?
Well you have to read the first line of the response and extract the status code. If it’s a 4xx or 5xx code something went wrong (404 = Not Found, 403 = Access Denied).