Hello! So, I am creating a C++ application that saves takes some metrics from the computer, and then upload them to a server (made with PHP) in order for the user to access the data later at some point.
This code that i created for this job, is posted bellow.
The string with the message, is taken with postman. Now the issue is that everything seems to execute well in the method, but i don't get any data on to my database. This is certainly NOT a PHP issue, because by hand it works. Any ideas what it might cause the problem ?
What I have tried:
This is is the code that i came up, that sends the http post request:
BOOL SendPostRequest(string server, string message)
{
struct sockaddr_in address;
unsigned long ulAddr;
SOCKET sock;
int connectResult;
int messageSize = strlen(message.c_str());
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
{
closesocket(sock);
return FALSE;
}
address.sin_family = AF_INET;
address.sin_port = htons(80);
ulAddr = inet_addr(server.c_str());
memcpy(&address.sin_addr, &ulAddr, sizeof ulAddr);
connectResult = connect(sock, reinterpret_cast<sockaddr*>(&address), sizeof address);
if (connectResult != 0)
{
closesocket(sock);
return FALSE;
}
send(sock, message.c_str(), messageSize, 0);
closesocket(sock);
return TRUE;
}
And i call/use it like this:
string message = "POST /submit.php?Url=www.example.com&Username=Revolution&Password=samplepassword HTTP/1.1"
"Host: localhost"
"Cache-Control: no-cache";
BOOL result = SendPostRequest("192.168.1.1", message);