The HttpGetText function is used to retrieve the contents
of a text resource and return it in a null-terminated string buffer.
Because binary data can include embedded null characters which
would truncate the string, this function should only be used with text
files or script output that is known to be textual. For example, it is
safe to use this function when a resource returns HTML or XML data, but
should not be used if it returns an image or executable file.
This function has been included as a convenience for applications
that need to retrieve relatively small amounts of textual data and
manipulate the contents as a string. If the Unicode version of this
function is called, the text is automatically converted to a Unicode
string. If the maximum amount of data being returned is unknown or the
amount of text is very large, it is recommended that you use the
HttpGetTextEx or HttpGetFile functions.
If the ANSI version of this function is called, the text returned
will always be UTF-8 encoded. If you need to return the text using a
different code page, use the HttpGetTextEx function which will
allow you to specify a different code page used for the conversion.
If you use the HttpGetFileSize function to determine how
large the string buffer should be prior to calling this function, it
is important to be aware that the actual number of characters may
differ based on the end-of-line conventions used by the host operating
system. For example, if you call HttpGetFileSize to obtain the
size of a text file on a UNIX system, the value will not be large
enough to store the complete file because UNIX uses a single linefeed
(LF) character to indicate the end-of-line, while a Windows system
will use a carriage-return and linefeed (CRLF) pair. To accommodate
this difference, you should always allocate extra memory for the
string buffer to store the additional end-of-line characters.
HTTP_EVENT_PROGRESS event will be periodically fired, enabling the
application to update any user interface controls. Event notification
must be enabled, either by calling HttpEnableEvents, or by
registering a callback function using the HttpRegisterEvent
function.
To determine the current status of a file transfer while it is in
progress, use the HttpGetTransferStatus function.
LPTSTR lpszBuffer = (LPTSTR)calloc(MAXFILESIZE, sizeof(TCHAR));
if (lpszBuffer == NULL)
return;
nResult = HttpGetText(hClient, lpszRemoteFile, lpszBuffer, MAXFILESIZE);