HttpGetText Function  
 
INT WINAPI HttpGetText(
  HCLIENT hClient,  
  LPCTSTR lpszResource,  
  LPTSTR lpszBuffer,  
  INT nMaxLength  
);

The HttpGetText function returns the contents of a text resource in a null-terminated string buffer.

Parameters

hClient
Handle to the client session.
lpszResource
A null-terminated string that specifies the resource that will be transferred to the local system. This may be the name of a file on the server, or it may specify the name of a script that will be executed and the output returned to the caller. This string may specify a valid URL for the current server that the client is connected to.
lpszBuffer
A null-terminated string buffer which will contain the contents of the text file when the function returns. This buffer should be large enough to store the contents of the file, including a terminating null character. This parameter cannot be NULL.
nMaxLength
An integer value that specifies the maximum number of characters that can be copied into the string buffer. This value must be larger than zero. If this value is smaller than the actual size of the text file, the data returned will be truncated.

Return Value

If the function succeeds, the return value is the server result code. If the function fails, the return value is HTTP_ERROR. To get extended error information, call HttpGetLastError.

Remarks

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.

Example

LPTSTR lpszBuffer = (LPTSTR)calloc(MAXFILESIZE, sizeof(TCHAR));

if (lpszBuffer == NULL)
    return;

nResult = HttpGetText(hClient, lpszRemoteFile, lpszBuffer, MAXFILESIZE);

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
Unicode: Implemented as Unicode and ANSI versions

See Also