gpt4 book ai didi

c++ - 防止 winHTTP 写入 STDOUT

转载 作者:行者123 更新时间:2023-11-30 05:41:13 25 4
gpt4 key购买 nike

我从 previous 中获取了以下代码所以帖子:

//Variables
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
std::vector <std::string> vFileContent;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;

// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"WinHTTP Example/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);

// Specify an HTTP server.
if (hSession)
hConnect = WinHttpConnect( hSession, L"stackoverflow.com",
INTERNET_DEFAULT_HTTP_PORT, 0);

// Create an HTTP request handle.
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET", L"/questions/ask/",
NULL, WINHTTP_NO_REFERER,
NULL,
NULL);

// Send a request.
if (hRequest)
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0,
0, 0);


// End the request.
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);

// Keep checking for data until there is nothing left.
if (bResults)
do{
// Check for available data.
dwSize = 0;
if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
printf( "Error %u in WinHttpQueryDataAvailable.\n",
GetLastError());

// Allocate space for the buffer.
pszOutBuffer = new char[dwSize+1];
if (!pszOutBuffer)
{
printf("Out of memory\n");
dwSize=0;
}
else
{
// Read the Data.
ZeroMemory(pszOutBuffer, dwSize+1);

if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
{
printf( "Error %u in WinHttpReadData.\n",
GetLastError());
}
else
{
printf("%s", pszOutBuffer);
// Data in vFileContent
vFileContent.push_back(pszOutBuffer);
}

// Free the memory allocated to the buffer.
delete [] pszOutBuffer;
}

} while (dwSize>0);


// Report any errors.
if (!bResults)
printf("Error %d has occurred.\n",GetLastError());

// Close any open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);

// Write vFileContent to file
std::ofstream out("./SO/ask.html",std::ios::app);
for (int i = 0; i < (int) vFileContent.size();i++)
out << vFileContent[i];
out.close();

运行时它会下载文件并打印其数据。我查看了代码,找不到将数据写入 STDOUT 的位置。谁能告诉我它的来源以及如何预防?

最佳答案

行:

printf("%s", ppszOutBuffer);

我相信是这里的原因。

关于c++ - 防止 winHTTP 写入 STDOUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31230864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com