Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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