当前,我正在使用 Wininet 来实现HTTP GET请求
下面,我尝试从服务器返回一个时间戳字符串
来触发GET请求 Goal
:获取该字符串的值
发送请求
HINTERNET hSession = InternetOpenA("MyAgent",
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect2 = InternetConnectA(hSession, "10.15.229.111",
8732, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest2 = HttpOpenRequestA(hConnect2, "GET",
"ovs/healthcheck", NULL, NULL, NULL, 0, 1);
HttpSendRequestA(hRequest2, NULL, 0, NULL , 0);
尝试获取响应字符串
DWORD dwContentLen;
DWORD dwBufLen = sizeof(dwContentLen);
if (HttpQueryInfo(hRequest2,
HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
(LPVOID)&dwContentLen,
&dwBufLen,
0))
{
DWORD dwReadSize = dwContentLen ;
DWORD dwBytesRead;
char *pCopyPtr = pData;
InternetReadFile(hRequest2, pCopyPtr, dwReadSize, &dwBytesRead);
pCopyPtr = dwBytesRead;
unsigned char datareturn[20];
memcpy(datareturn, &pData, 20);
std::cout << datareturn; }
快速问题:pData是否从GET请求返回响应字符串。
作为c ++的新手,任何见识都会很棒。谢谢您的时间