Hello ,
I am sending a gif file to the HTTP Server.
Is there any way to find that the file is transfered successfully.
If yes how?
INTERNET_BUFFERS BufferIn = {0};
DWORD dwBytesRead;
DWORD dwBytesWritten;
BYTE pBuffer[1024];
BOOL bRead, bRet;
HANDLE hFile;
HINTERNET hSession = InternetOpen(NULL,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0);
HINTERNET hConnection = InternetConnect(hSession,
_T("www.crmpanel.com"),
INTERNET_DEFAULT_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
NULL);
BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );
HINTERNET hRequest = HttpOpenRequest(hConnection,
_T("PUT"),
_T("/temp"),
NULL,
NULL,
NULL,
0,
0);
if (!hRequest)
{
MessageBox(_T("Failed to open request handle:"),NULL,MB_OK);
return ;
}
hFile = CreateFile (_T("c:\\Image1.gif"),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
MessageBox(_T("Failed to open local file"),NULL,MB_OK);
return ;
}
BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
MessageBox(_T("File size is"),NULL,MB_OK);
if(!HttpSendRequestEx(hRequest, &BufferIn, NULL, HSR_INITIATE, 0))
{
MessageBox(_T("Error on HttpSendRequestEx"),NULL,MB_OK);
return ;
}
DWORD sum = 0;
do
{
if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),
&dwBytesRead, NULL)))
{
MessageBox(_T("ReadFile failed on buffer"),NULL,MB_OK);
break;
}
if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
&dwBytesWritten)))
{
MessageBox(_T("InternetWriteFile failed"),NULL,MB_OK);
break;
}
sum += dwBytesWritten;
}
while (dwBytesRead == sizeof(pBuffer)) ;
CloseHandle (hFile);
MessageBox(_T("Actual written bytes:"),NULL,MB_OK);
if(!HttpEndRequest(hRequest, NULL, 0, 0))
{
MessageBox(_T("Error on HttpEndRequest"),NULL,MB_OK);
return ;
}
return ;
Please help me.
Thanks In Advance
modified on Friday, December 5, 2008 5:52 AM
|