Solved

Is there a way to determind the filesize of a HTTP file from c++??

Posted on 2004-09-29
5
171 Views
Last Modified: 2013-12-03
Hi,

I need to get the EXACT filesize of
http://people.zeelandnet.nl/marco1974/about.bmp

for example.

Just in plain c++ code using  WININET.LIB and   WININET.H

I need a few functions for Filese :
and The FileDate and time TOO.

Thanks for helping.

Best regards,

marco
0
Comment
Question by:marco_coder
[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
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12181642
Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;234913 ("How To Provide Download/Upload Progress Information when Using WinInet"). It retrieves the size of the file using

    DWORD dwContentLen;
    DWORD dwBufLen = sizeof(dwContentLen);
    if (HttpQueryInfo(hRequest,
                      HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
                      (LPVOID)&dwContentLen,
                      &dwBufLen,
                      0))


'HTTP_QUERY_LAST_MODIFIED' will give you the date and time.
0
 

Author Comment

by:marco_coder
ID: 12181811
pLEASE a working sample please, i am bad at internet.

like void print_file_size_in_msg_BOX()
{

Getsize from web
Messagebox etc.


}



I am still in my learning curve.
And i have trouble.

0
 
LVL 86

Accepted Solution

by:
jkr earned 390 total points
ID: 12182063
#include <windows.h>
#include <wininet.h>
#include <iostream>
using namespace std;

DWORD GetObjectSize ( char* pszHost, char* pszFile) {

      DWORD dwFileSize = 0;

    HINTERNET hSession = InternetOpen("HTTPSize",
                                      INTERNET_OPEN_TYPE_PRECONFIG,
                                      NULL,
                                      NULL,
                                      0);
    HINTERNET hConnection = InternetConnect(hSession,
                                            pszHost,  // Server
                                            INTERNET_DEFAULT_HTTP_PORT,
                                            NULL,     // Username
                                            NULL,     // Password
                                            INTERNET_SERVICE_HTTP,
                                            0,        // Synchronous
                                            NULL);    // No Context

    HINTERNET hRequest = HttpOpenRequest(hConnection,
                                         "GET",
                                         pszFile,
                                         NULL,    // Default HTTP Version
                                         NULL,    // No Referer
                                         (const char**)"*/*\0", // Accept
                                                                // anything
                                         0,       // Flags
                                         NULL);   // No Context
    HttpSendRequest(hRequest,
                    NULL,    // No extra headers
                    0,       // Header length
                    NULL,    // No Body
                    0);      // Body length

    DWORD dwContentLen;
    DWORD dwBufLen = sizeof(dwContentLen);
    if (HttpQueryInfo(hRequest,
                      HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
                      (LPVOID)&dwContentLen,
                      &dwBufLen,
                      0)) {

            dwFileSize = dwContentLen;
      }

      InternetCloseHandle(hRequest);
      InternetCloseHandle(hConnection);
      InternetCloseHandle(hSession);

      return dwFileSize;

}

void main () {

    cout << GetObjectSize ( "people.zeelandnet.nl","marco1974/about.bmp") << endl;
}

Your bitmap is 11702 bytes, BTW.

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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