Http post request code
BYTE* DoPostRequest(std::wstring ip, int port, std::wstring path, std::string data)
{
HINTERNET hHttpSession, hHttpRequest, hIntSession;
DWORD timeout;
DWORD dwRead;
hIntSession = InternetOpen(L"Somerandomshiz" //Utils::StringToWString(XorStr()).c_str()
, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!hIntSession)
std::cout << "hIntSession Faild" << std::endl;
timeout = 300 * 1000;
if (!InternetSetOption(hIntSession, INTERNET_OPTION_RECEIVE_TIMEOUT, &timeout, sizeof(timeout)) ||
!InternetSetOption(hIntSession, INTERNET_OPTION_SEND_TIMEOUT, &timeout, sizeof(timeout)) ||
!InternetSetOption(hIntSession, INTERNET_OPTION_CONNECT_TIMEOUT, &timeout, sizeof(timeout)))
std::cout << "!InternetSetOption(hIntSession, INTERNET_OPTION_RECEIVE_TIMEOUT, &timeout, sizeof(timeout)) Faild" << std::endl;
hHttpSession = InternetConnect(hIntSession, ip.c_str(), port, 0, 0, INTERNET_SERVICE_HTTP, 0, NULL);
if (!hHttpSession)
std::cout << "hHttpSession Faild" << std::endl;
hHttpRequest = HttpOpenRequest(
hHttpSession,
L"POST",
path.c_str(),
0, 0, NULL, INTERNET_FLAG_RELOAD, 0);
if (!hHttpRequest)
std::cout << "hHttpRequest Faild" << std::endl;
std::string szHeaders = "Content-Type: application/x-www-form-urlencoded;\r\nContent-Length: ";
szHeaders += std::to_string(data.length());
if (!HttpSendRequestA(hHttpRequest, szHeaders.c_str(), szHeaders.length(), (LPVOID)data.c_str(), data.length()))
std::cout << "HttpSendRequestA Faild" << std::endl;
//payload
const int BUFFERSIZE = 7 * 1000 * 1000; //7mb
dwRead = 0;
CHAR* szAsciiBuffer = new CHAR[BUFFERSIZE];
memset(szAsciiBuffer, 0, BUFFERSIZE);
InternetReadFile(hHttpRequest, szAsciiBuffer, BUFFERSIZE, &dwRead);
InternetCloseHandle(hHttpRequest);
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hIntSession);
return (BYTE*)szAsciiBuffer;
}
我的电话
auto response = (char*)g_pUtilis->DoPostRequest(
L"localhost", 80, L"test.php",
std::string("id=") + "231"
);
PHP代码
echo "test";
我得到了什么 - Result Picture
编辑: 它似乎抓住其他信息很好,只有当我使用PHP回声/只是让PHP返回任何东西。有任何想法吗?我在da internet上找不到太多信息。
提前致谢:)
编辑: 仍然有这个问题无法弄明白。 所以
echo "1234";
exit;
基本上在浏览器中输出1234但在我的控制台中使用POST它返回 - 1234234
0 //我不知道0来自哪里。 Raw Image
这似乎只发生在namecheap.com服务器上。它在OVH VPS网络服务器以及000webhost.com / hosting24.com上运行良好(同样的事情吧?:P)
如果有任何人知道什么是PLZ帮助我不想花更多的钱 只是因为这个bug。