![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 2
Rep Power: 0
![]() |
I have wrote a web server by C language.
but I don't know how to send back error page to web browser if user type wrong web address or name that will show HTTP/1.0 404 NOT FOUND. One more is how I can stop server socket sending rubbish code if the requested files are sent competely. Thanks |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Theres no way we can tell you how to fix your code if we dont have it..
__________________
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
Well, the code itself doesn't exactly need fixed. I think he is asking how servers do this in general..
I'm not sure how this works myself, but if I had to guess I would think it would have something to do wtih some sort of if statement. If certain directory or file doesn't exist, then send errorPage.html. Something a long those lines. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
Well if he wrote a HTTP server, then he should be able to write basic code like that... but what i said was basically acting on the idea that he didnt know how to format the response packet that could send a 404. And as for stopping the code from sending rubbish at the end of the packet, thats a logic error which i would have to see to correct.
Edit: Oh yea, and if the question is how to setup the packet, use telnet or ethereal and capture a 404 packet from a site.
__________________
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Nov 2004
Posts: 24
Rep Power: 0
![]() |
a 404 is identical to any other response.
if we look at a HTTP response message: ---- {RESPONSE LINE}\r\n {HEADERS}\r\n \r\n {MESSAGE} ---- where {RESPONSE LINE} is as follows: {HTTP_VERSION} {STATUS_CODE} {STATUS_STRING} The status code is used by the browser to determine the outcome of a request for example 200 for "OK" and 404 for "NOT FOUND", the status string is for the user. When a user makes a request for a page that is valid, you will I am guessing be sending: --- HTTP/1.1 200 OK\r\n \r\n {FILE CONTENT} --- so finally we get to an error, when the page requested is not found: --- HTTP/1.1 404 Not Found\r\n \r\n {ERROR PAGE} --- when the file that the user is requesting is not available, you can switch to an error page and send that instead, the browser would still recognize it as an error! hope it helps, you don't need to capture packets thats a lil extreme for me anyway -phrosys |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|