-
February 18th, 2008, 09:01 PM
#1
Downloading file via HTTP connection using CHttpFile fails
Hi everyone:
Here's a code snippet I was intending to use to download files via HTTP connection:
Code:
LPCTSTR pURL = _T("http://www.google.com");
//Open session
CInternetSession InetSess(_T("my prog"));
//Get pointer to CHttpFile
CHttpFile* pHttpFile = (CHttpFile*)InetSess.OpenURL(pURL, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD);
if(pHttpFile)
{
//Get size of file
ULONGLONG ncbSz64 = pHttpFile->GetLength();
ULONG ncbSz = (ULONG)ncbSz64;
if(ncbSz == ncbSz64)
{
//Reserve data
pBuff = new BYTE[ncbSz];
if(pHttpFile->Read((BYTE*)pBuff, ncbSz) != ncbSz)
{
//Success!
}
}
}
Somehow when it runs, pHttpFile->Read returns success and correct file length read but the memory at pBuff is filled out only to the first 200-300 characters. I never programmed HTTP before, what am I not doing right?
-
February 19th, 2008, 05:23 PM
#2
Re: Downloading file via HTTP connection using CHttpFile fails
Why you are not using: ::URLDownloadToFile () ?
Cheers
-
February 20th, 2008, 02:54 AM
#3
Re: Downloading file via HTTP connection using CHttpFile fails
Hmm. I don't know. I didn't come across that API. I'll give it a try. Still what about the sample above?
-
February 20th, 2008, 06:04 AM
#4
Re: Downloading file via HTTP connection using CHttpFile fails
You need to get the connection after session to obtain the HttpFile,
Steps in a Typical HTTP Client Application
Regards,
Ramkrishna Pawar
-
February 20th, 2008, 10:05 PM
#5
Re: Downloading file via HTTP connection using CHttpFile fails
Originally Posted by Krishnaa
Thanks alot! That's what I was missing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|