【发布时间】:2014-02-01 20:35:48
【问题描述】:
我正在尝试通过 WinHTTP 读取网页:
bool WinHTTPClass::QueryResponseData(std::string &query_data)
{
// Read response
DWORD dwSize, dwDownloaded = 0;
do
{
// Check for available data.
if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
{
cout << "Error querying data : " << GetLastError() << endl;
return false;
}
// Allocate space for the buffer.
char* pszOutBuffer = new char[dwSize+1];
if( !pszOutBuffer )
{
cout << "Out of memory" << endl;
dwSize=0;
}
else
{
// Read the data.
ZeroMemory( pszOutBuffer, dwSize+1 );
if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded ) )
{
cout << "Error reading data : " << GetLastError() << endl;
return false;
}
else
{
query_data += pszOutBuffer;
}
// Free the memory allocated to the buffer.
delete [] pszOutBuffer;
}
}
while( dwSize > 0 );
return true;
}
这一切都很好。我在这里遇到的困惑是我应该使用 unicode 编码缓冲区而不是处理缓冲区数据:
char* pszOutBuffer = new char[dwSize+1];
比如用wchar_t代替网页常用的UTF8?有什么不同?我哪里糊涂了?
【问题讨论】: