Solved

Problems with CHttpFiles

Posted on 2000-02-24
2
538 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

724 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