Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems with CHttpFiles

Posted on 2000-02-24
2
Medium Priority
?
552 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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