hi.
im implementing a tcp http request with sdl net and i could not find much resources about it so it would be great if some one can take a look and tell me if im doing it the right way?
the server side that receive the call is a php file that do echo.
in the response im getting
30
the response
0
what are the 30 and 0 are?
this is the code:
TCPsocket socket;
SDLNet_SocketSet sockets;
IPaddress ip;
SDLNet_Init();
SDLNet_ResolveHost(&ip, "aaa.aaa.com", 80);
socket = SDLNet_TCP_Open(&ip);
sockets = SDLNet_AllocSocketSet(1);
std::string send_data = "";
send_data.append("POST /path/file.php HTTP/1.1\r\n");// HTTP/1.1\r\n
send_data.append("Host: aaa.aaa.com\r\n");
send_data.append("Connection: close\r\n");
send_data.append("Content-Type: application/x-www-form-urlencoded\r\n");
send_data.append("Content-Length: 11\r\n");
send_data.append("\r\n");
send_data.append("AA=aa&BB=bb");
int send_data_length = (int)send_data.length();
int buffer_size = 4096;
char* buffer = new char[buffer_size];
int sent_length = SDLNet_TCP_Send(socket, send_data.c_str(), send_data_length);
if (sent_length == send_data_length)
{
std::string recived_data;
int length;
do {
length = SDLNet_TCP_Recv(socket, (void*)buffer, buffer_size);
for (int i = 0; i < length; ++i)
{
recived_data.push_back(buffer[i]);
}
} while (length > 0);
delete[] buffer;
int content_start = (int)recived_data.find("\r\n\r\n");
SDL_Log(recived_data.c_str());
SDL_Log("__________________");
SDL_Log(recived_data.substr(content_start).c_str());
SDL_Log("__________________");
}
SDLNet_FreeSocketSet(sockets);
SDLNet_TCP_Close(socket);
this is the php script
<?php
$AA = $_POST['AA'];
$BB = $_POST['BB'];
echo "abc 123 ^|*. $AA $BB";
echo "nexta";
echo "$AA $BB";
echo "nextb";
echo $AA;
echo "nextc";
echo $BB;
echo "nextd";
echo ".";
?>
and this is the response
INFO: HTTP/1.1 200 OK
Connection: close
Date: Sat, 29 Dec 2018 10:37:18 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
Via: 1.1 vegur
30
abc 123 ^|*. aa bbnextaaa bbnextbaanextcbbnextd.
0
INFO: __________________
INFO:
30
abc 123 ^|*. aa bbnextaaa bbnextbaanextcbbnextd.
0
INFO: __________________