C ++套接字HTTP发布请求问题

时间:2014-08-11 23:44:21

标签: php html c++ sockets httprequest

我正在尝试发帖请求,但我遇到了一些问题。

如果我输入CPUKey和Hash,我可以发送请求并得到响应

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 \ n \ n内容长度:65 \ r \ n \ nCPUKey =%s& hash =%s \ r \ n \ nConnection:close“,”12121212121212121212121212121212“,”00000000000000000000“);

有效,但当我实际用CPUKeyBuffer和HashBuffer替换121212121和000000时,它不会发送数据。我不明白我做错了什么。谁能告诉我我遇到的问题?

PS LinkChar基本上是sprintf但是返回缓冲区并且在我使用的其他所有内容上工作正常

由于

1 个答案:

答案 0 :(得分:0)

字符串分隔符(标题之间以及起始行和第1个标题之间)不准确:\ r \ n必须在任何地方(根据RFC2616,CR LF)。您有时使用\ n,有时\ r \ n \ n。没有主体的请求必须以\ r \ n \ r \ n结尾(最后一个标题和空字符串)