Nov 12, 2009 at 6:53pm UTC
CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//(...)
char * metod=strtok(request," " );
char * object=strtok(NULL," " );
char * protocol=strtok(NULL,"\n" );
object=strtok(object,"/" );
char response[1000];
const char * response_404 = "404 Not Found\n" ;
const char * html_response_404 = "<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL was not found on this server.</p>\n</body><html>\n" ;
sprintf(response,"%s %s\n%s" ,protocol,response_404,html_response_404);
cout << response << endl;
OUT:
404 Not Found
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body><html>
SHOULD BE:
HTTP/1.1 404 Not Found
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body><html>
What am I doing wrong?
Last edited on Nov 13, 2009 at 12:40am UTC
Nov 12, 2009 at 7:13pm UTC
Please use [co de][/code] tags
You are missing the opening double-quotes sign:
sprintf(response,%s %s\n%s",protocol,response_404,html_response_404);
response
is not big enough
Last edited on Nov 12, 2009 at 7:13pm UTC
Nov 12, 2009 at 7:34pm UTC
Can you post the code you have for _404 strings declaration?
The code above should work fine
Nov 12, 2009 at 7:39pm UTC
Here it is (edited above).
Nov 12, 2009 at 7:56pm UTC
That code should work. The only issue I see is that the names don't match but that seems only a copy-paste error
Is protocol ever changing the address it's pointing to?