Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in HTTPrequest/response for a web server application

Status
Not open for further replies.

andygbc

Programmer
Jul 20, 2003
2
SG
Currently i am developing a web server application in console. I am using a browser to connect to the host running this application. The server is able to receive the http request from the browser. The problem come in, what should i send in response? Below is a response i write but the browser did not display anything at all. What is wrong here?can anyone help me?

strcpy(szBuf, "HTTP/1.1 500 Server Error \nDate: Fri, 31 Dec 1999 23:59:59 GMT Content-Type: text/html Content-Length: 219");

if (send(s,szBuf,strlen(szBuf),0) == SOCKET_ERROR)
{
closesocket(s);
}
 
First of all, in your response you need more newlines, i.e.

"HTTP/1.1 500 Server Error \nDate: Fri, 31 Dec 1999 23:59:59 GMT Content-Type: text/html Content-Length: 219"

should become

"HTTP/1.1 500 Server Error\nDate: Fri, 31 Dec 1999 23:59:59 GMT\nContent-Type: text/html\nContent-Length: 219"


Another thing. Why do you have Content-type: text/html and Content-length: 219? It appears to me that you aren't sending any entity at all, just the headers. If you send just the headers (without any content-type or content-length specified), most browsers will generate an error message for the user to the see (for example, Internet Explorer says "This page cannot be displayed")

Now I don't know about you but that date looks wrong too. [lol]

Good luck.


[sub]I REALLY hope that helps.[/sub]
Will
 
I have tried using the way you said but it still does not have any effect on the client browser? what is the problem?

I have tried this:
"HTTP/1.1 500 Server Error\nDate: Fri, 31 Dec 1999 23:59:59 GMT\nContent-Type: text/html\nContent-Length: 219"

And this:
"HTTP/1.1 500 Server Error\n"

The browser only said page cannot be display.Should it display a server Error msg? The reason why i add the content type and length is because i wanted to send a html file back but now i doing a test try on the error message first. Is the date and time send important? can anyone help on the error msg first?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top