Solved

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

Posted on 2004-09-29
5
167 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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