PGHULME wrote:
> Hi
>
> I have started writing an app(in c and compiled with gcc) that delivers
>
> html pages (aptly named a web server). my current code for sending the
> http header and code looks like this:
> // send header
> send(clntSocket, "HTTP/1.1 200 OK\n", 16, 0);
> send(clntSocket, "Content-type: text/html\n", 25, 0);
> send(clntSocket, "Content-length:\n\n", 18, 0); //extra line feed for
> http spec
> //html code
> send(clntSocket, "<HTML>", 6, 0);
> send(clntSocket, "<HEAD>", 6, 0);
> send(clntSocket, "<TITLE>", 7, 0);
> send(clntSocket, "A Small Hello", 13, 0);
> send(clntSocket, "</TITLE>", 8, 0);
> send(clntSocket, "</HEAD>", 7, 0);
> send(clntSocket, "<BODY>", 6, 0);
> send(clntSocket, "<H1>Hi</H1>", 11, 0);
> send(clntSocket, "<P>This is very minimal hello world HTML
> document.</P>", 55, 0);
> send(clntSocket, "</BODY>", 7, 0);
> send(clntSocket, "</HTML>", 7, 0);
> //close socket
> close(clntSocket);
>
>
> this is just to test the socket connection. The problem is, i try to
> use internet explorer or firefox to connect to the server and retrieve
> this test page. Both web browsers connect to the server but both fail
> to load the page. Internet explorer complains that it cannot find
> server. and firefox says that the connection was reset before the page
> could be loaded. The thing is though, if i use wget to connect to the
> server, it does manage to download the test page correctly. I have read
>
> through the http specs, and they say that the header should be sent
> followed by a new line (/n) then the data/html, once this is sent the
> connection should then be closed. I have followed those specs but i am
> unable to see why the code works when wget is connecting but not when
> web browsers try.... anyone got any ideas????
Telnet to the server, and manually issue the GET command.
If the result is equal to what you would expect then it does not lie in
the headers, or content - you have messed up the HTTP conversation, and
wget is merely very very forgiving.
J