Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Error Since Excel 2016 x64 5 141
Runtime error 76: path not found error VB6 program on Windows 7 3 640
Problem to file 3 92
Visual Studio hangs on running project 6 57
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…

761 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