Solved

Problems with CHttpFiles

Posted on 2000-02-24
2
533 Views
Last Modified: 2013-11-20
I need to download a file from a server and my problem is that the size of the file is wrong.  Here's my code:

pHttpFile = (CHttpFile*)(session.OpenURL( "http://netdev1/~foo/bar/bar.ini"));

pHttpFile->SendRequest("", NULL, 0);

DWORD dwStatus;
pHttpFile->QueryInfoStatusCod(dwStatus);            

if (dwStatus < 200 || dwStatus > 299)
      AfxThrowInternetException(pConnection->GetContext());

CString csFilename = APPINFO->GetAppRootPath() + "bar.ini";
                  CFile fileLocal(csFilename,
                        CFile::modeCreate | CFile::modeWrite);

int iLen = pHttpFile->GetLength();
BYTE* pBuf = new BYTE[iLen];
pHttpFile->Read(pBuf, iLen);

fileLocal.Write(pBuf, iLen);
fileLocal.Close();

pHttpFile->Close();

The problem is that the GetLenght method does not return the right size but the file is all here because if I change the value of iLen before it is used and set it to the right size everything is fine!
0
Comment
Question by:davidmorand
2 Comments
 

Author Comment

by:davidmorand
ID: 2556019
BTW, the size returned seems to be pretty random but around 700 bytes...
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 75 total points
ID: 2556216
Your code is not right.

Casting the return value of CInternetSession::OpenURL() is the wrong thing to do.

Calling SendRequest() on the file returned from OpenURL() is wrong, as well.

You can either:

1) Remove the cast. Remove the call to SendRequest().

or

2) Call CInternetSession::OpenHttpConnection(). Call CHttpConnection:OpenRequest(). Call CHttpFile::SendRequest().

..B ekiM
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now