Solved

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

Posted on 2004-09-29
5
165 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
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
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
Comment Utility
#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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

10 Experts available now in Live!

Get 1:1 Help Now