?
Solved

Problems with CHttpFiles

Posted on 2000-02-24
2
Medium Priority
?
544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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