CHttpClient::GetContentLength Method  
 
BOOL GetContentLength(
  LPDWORD lpLength  
);

BOOL GetContentLength(
  ULARGE_INTEGER *lpLength  
);

The GetContentLength method returns the size of the current resource in bytes.

Parameters

hClient
Handle to the client session.
lpLength
A pointer to a unsigned integer which will contain the content length for the current resource. This value will be initialized to zero and updated with the length when the method returns. If it's possible the server will return more than 4GiB of data to the client, this parameter should point to an unsigned 64-bit integer.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

When this method is called after a GET or POST request has completed, the lpLength parameter will contain the total number of bytes returned by the server. If this method is called while a request is being processed (for example, from within an event handler), it will return the value of the Content-Length response header provided by the server.

Most servers will only include a Content-Length header in the response for static resources like documents or image files. For other types of resources where the response payload is generated dynamically, such as server-side scripts, servers typically use "chunked" output and there is no Content-Length header.  The server may also not provide a file size for HTML documents which use server side includes (SSI) because that content is also dynamically created by the server. In this case, the content length can only be determined after the request has completed.

This method should only be used after a request has completed and will not return a value for dynamic resources as they are being retrieved from the server. To obtain the current number of bytes copied from within an event handler, use the GetTransferStatus method.

If the content type for the current resource is textual, the content length reported by the server may be different than what is stored on the local system due to different end-of-line character conventions. For example, on Windows the end of a line of text is indicated by a carriage-return and linefeed pair, while on Linux the end-of-line is indicated by a single linefeed. Depending on the options specified when the request is made, text returned by the server may be normalized for the Windows platform.

This method does not use the HEAD command to request the size of a document on the server. It will only return the content length of a resource which has already been requested, typically after using methods such as GetText or PostXml. To ask the server for the size of document without downloading the contents of that document, use the GetFileSize method.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtpv12.lib

See Also