简体   繁体   中英

C++ Sockets HTTP Post Request Problems

Im trying to do a post Request and im having some problems.

I can send the request and get a response if i type the CPUKey and Hash like so

GetModuleHash(XEXHASH);
CharStr2HexStr(XEXHASH, HashBuffer, 10);
if (!ServerConnect(SERVER, 80))
    return false;
DebugPrint("Connection Established");
char* Test = LinkChar("POST /projects/xenium-mw3-menu/auth.php HTTP/1.1\nHost: www.xeniummodding.com\nContent-type: application/x-www-form-urlencoded\r\nContent-length: 65\r\n\nCPUKey=%s&hash=%s\r\nConnection: close", "12121212121212121212121212121212", "00000000000000000000");
NetDll_send(XNCALLER_SYSAPP, sock, Test, strlen(Test), 0);
NetDll_recv(XNCALLER_SYSAPP, sock, ReturnBuffer, sizeof(ReturnBuffer), 0);
NetDll_closesocket(XNCALLER_SYSAPP, sock);
if (strstr(ReturnBuffer, "Auth Result: 1"))
{
    DebugPrint("Data Recieved: 1");
    return true;
}
else
{
    DebugPrint("Data Recieved: 0");
    return false;
}

char* Test = LinkChar("POST /projects/xenium-mw3-menu/auth.php HTTP/1.1\\nHost: www.xeniummodding.com\\nContent-type: application/x-www-form-urlencoded\\r\\nContent-length: 65\\r\\n\\nCPUKey=%s&hash=%s\\r\\nConnection: close", "12121212121212121212121212121212", "00000000000000000000");

that works but when i actually replace the 121212121 and 000000 with CPUKeyBuffer and HashBuffer it does not send the data. i dont understand what im doing Wrong. Can anyone tell me the problem i am having?

PS LinkChar is basically sprintf but returning the buffer and works fine on everything else i use

Thanks

You are inaccurate with string dividers (between headers and between start line and the 1st header): \\r\\n must be everywhere (CR LF in terms of RFC2616). You are using sometimes \\n, sometimes \\r\\n\\n. The request w/o body has to be end with \\r\\n\\r\\n (last header and empty string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM