描述:
C++的第一个任务,实现上传功能的activeX控件。要断点续传。 一点思路都没有。大家给点意见吧,谢谢
解决方案1:
我这两天也搞这个,不过上传不成功.不知道什么原因,代码如下:
DWORD dwHttpRequestFlags= INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_TRANSFER_BINARY;
CString csServer = "127.0.0.1";
INTERNET_PORT nPort = 80;
CInternetSession *pSession = new CInternetSession("upload");
CHttpConnection *pHttpConn = NULL;
pHttpConn = pSession->GetHttpConnection(csServer, nPort);
CHttpFile *pHttpFile = NULL;
CString csFile = "/aa.txt";
pHttpFile = pHttpConn->OpenRequest(CHttpConnection::HTTP_VERB_PUT, csFile, NULL, 1, NULL, NULL, dwHttpRequestFlags);
ASSERT( pHttpFile != NULL );
CFile File;
File.Open("C:\\aa.txt", CFile::modeRead);
int nLen = File.GetLength();
char *buffer = new char[nLen];
memset(buffer, 0, nLen);
File.Read(buffer, nLen);
File.Close();
/*INTERNET_BUFFERS BufferIn;
DWORD dwBytesWritten;
BOOL bRet;
BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); // Must be set or error will occur
BufferIn.Next = NULL;
BufferIn.lpcszHeader = NULL;
BufferIn.dwHeadersLength = 0;
BufferIn.dwHeadersTotal = 0;
BufferIn.lpvBuffer = NULL;
BufferIn.dwBufferLength = 0;
BufferIn.dwBufferTotal = nLen; // This is the only member used other than dwStructSize
BufferIn.dwOffsetLow = 0;
BufferIn.dwOffsetHigh = 0;*/
//int res = pHttpFile->SendRequestEx(&BufferIn,NULL,HSR_INITIATE,0);
int res = pHttpFile->SendRequestEx(nLen);
if (res == 0)
MessageBox("send error.");
pHttpFile->Write(buffer, nLen);
pHttpFile->EndRequest();
pHttpFile->Close();
delete pHttpFile;
pHttpConn->Close();
delete pHttpConn;
pSession->Close();
delete pSession;
delete []buffer;
buffer = NULL;