C++ 如何在C++;将文件发送到浏览器
我需要将文件从我的目录发送给用户。未发送问题文件。 有人能帮我吗 我的代码如下:C++ 如何在C++;将文件发送到浏览器,c++,windows,http,file-upload,C++,Windows,Http,File Upload,我需要将文件从我的目录发送给用户。未发送问题文件。 有人能帮我吗 我的代码如下: CHttpServerContext* pCtxt; // ... there i set headers for open DWORD dwRead; CString fileName = "c:\txt.doc"; HANDLE hFile = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ, (LPSECURIT
CHttpServerContext* pCtxt;
// ... there i set headers for open
DWORD dwRead;
CString fileName = "c:\txt.doc";
HANDLE hFile = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, (HANDLE) NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return;
}
int c = 0;
CHAR szBuffer [2048];
do
{
if (c++ > 20) {
break;
return;
}
// read chunk of the file
if (!ReadFile (hFile, szBuffer, 2048, &dwRead, NULL))
{
return;
}
if (!dwRead)
// EOF reached, bail out
break;
// Send binary chunk to the browser
if (!pCtxt->WriteClient( szBuffer, &dwRead, 0))
{
return;
}
}
while (1);
CloseHandle (hFile);
}
医生,我病了。我怎么了 我是说,你几乎没有透露发生了什么
CHttpServerContext
TransmitFile
功能医生,我病了。我怎么了 我是说,你几乎没有透露发生了什么
CHttpServerContext
TransmitFile
功能重新发明控制盘没有意义-只需使用TransmitFile API即可-它是内置的。重新发明控制盘没有意义-只需使用TransmitFile API即可-它是内置的。您是否观察到类似Fiddler的HTTP传输?这与其他HTTP回复相比如何?您是否观察到类似Fiddler的HTTP传输?这与其他HTTP回复相比如何?