Downloading file via HTTP connection using CHttpFile fails
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Downloading file via HTTP connection using CHttpFile fails

  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    827

    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?

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: Downloading file via HTTP connection using CHttpFile fails

    Why you are not using: ::URLDownloadToFile () ?

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    827

    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?

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    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

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    827

    Re: Downloading file via HTTP connection using CHttpFile fails

    Quote Originally Posted by Krishnaa
    You need to get the connection after session to obtain the HttpFile,

    Steps in a Typical HTTP Client Application
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center