AJAX response not valid in C++ but Apache
Posted
by
fehergeri
on Stack Overflow
See other posts from Stack Overflow
or by fehergeri
Published on 2011-02-01T11:26:05Z
Indexed on
2011/02/03
23:26 UTC
Read the original article
Hit count: 304
I want to make a server written in C++ to power my game. I learned the basics of sockets and wrote a basic chat program that worked well. Now I want to create an HTTP server like Apache, but only for the AJAX request-response part.
I think just for the beginning i copied one Apache response text, and i sent the exact response with the C++ server program.
The problem that is that the browser (Firefox) connnects to the apache and everything works fine, except all of the requests get a correct response.
But if i send this with the C++ client, then FireBug tells me that the response status is OK (200) but there is no actual response text. (How is this possible?)
This response-text is exactly the same what apache sends. I made a bit-bit comparison and they were the same.
The php file wich is the original response
<?php echo "AS";echo rand(0,9); ?>
And the origional source code:
- Socket.h http://pastebin.com/bW9qxtrR
- Socket.cpp http://pastebin.com/S3c8RFM7
- main.cpp http://pastebin.com/ckExuXsR
- index.html http://pastebin.com/mcfEEqPP < this is the requester file.
- ajax.js http://pastebin.com/uXJe9hVC
- benchmark.js http://pastebin.com/djSYtKg9
jQuery is not needed.
The main.cpp there is lot of trash code like main3 and main4 functions, these do not affect the result.
I know that the response stuff in the C++ code is not really good because the connection closing is not the best; I will fix that later now I want to send a success response first.
UPDATE:
now i tested today a lot again and i find out there is no problem with the socket. I used the fiddler program to capture the the good answer and to capture the bad. They were the same. After this i turned off my socket application, and forced fiddler to auto respond, and the answer from the 'bad' answer still bat. So after that i replaced the bad with the good and nothing happedned. The bad answer with the good text still bad on the :8888 port but the other on the original :80 port was good, but they were absolutly the same and the same program sended it (fiddler) i think there is something missing if the response is not on the same server address (even not the same port).
UPDATE:
oh my god! i cant send ajax request to a remote server. now i know this.
© Stack Overflow or respective owner