CHttpClient::GetContentType Method  
 
INT GetContentType(
  LPTSTR lpszContentType,  
  INT nMaxLength  
);

The GetContentType method returns the content type for the current resource.

Parameters

hClient
Handle to the client session.
lpszContentType
A pointer to a buffer which will contain the MIME content type of the resource returned by the web server. The buffer must be large enough to contain the entire content type string including the terminating null character. This parameter is optional and may be NULL if the information is not required.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the buffer. If the lpszContentType parameter is NULL, this value must be zero.

Return Value

If the method succeeds, the value indicates the type of resource returned by the server. If the method fails, the return value is HTTP_ERROR. To get extended error information, call GetLastError.

Value Description
HTTP_CONTENT_UNKNOWN The content type for the resource could not be determined. This can occur if the content type returned by the server does not match a known value, such as an experimental or non-standard content type.
HTTP_CONTENT_BINARY Application specific binary data which doesn't explicitly fall into any of the other standard MIME types. The most common type for binary data is application/octet-stream which can represent any type of data. Other examples are application/pdf and application/zip.
HTTP_CONTENT_TEXT Textual data which can include plain text, HTML documents, XML, comma-separated value (CSV) data or any other human readable text formats. Examples are text/plain and text/html.
HTTP_CONTENT_AUDIO Audio data which can include MEPG audio and Windows Media formats. Examples are audio/mpeg, audio/mp4 and audio/x-ms-wma.
HTTP_CONTENT_IMAGE Image data which can include GIF, JPEG and PNG image formats. Examples are image/gif and image/jpeg.
HTTP_CONTENT_MESSAGE A content type which specifies the response includes other messages, typically email messages in a standard MIME format. This content type is not commonly used with web services.
HTTP_CONTENT_MULTIPART A content type which includes multiple types of data in a single response. The payload will typically be encoded text and the contents will need to be decoded to extract any binary data included in the message.
HTTP_CONTENT_VIDEO Video data which can include MP4 movies or Window Media format video. Examples are video/mp4 and video/x-ms-wmv.
HTTP_CONTENT_FONT Font data which can include TrueType and OpenType fonts. Examples are font/tff and font/otf.
HTTP_CONTENT_MODEL Model data for 3D objects and scenes, such as those used with the Virtual Reality Modeling Language (VRML). Examples are model/3mf and model/vrml.

Remarks

This method does not examine the contents of the payload returned by the server and only returns a value based on the Content-Type response header. If the web server does not recognize the data format of the resource it is returning, it should identify it as application/octet-stream and the content type would be returned as HTTP_CONTENT_BINARY. However, some servers incorrectly return unrecognized formats as text/plain, causing the payload to be identified as human-readable text rather than binary data.

Some servers will return a content type of text/plain for JSON responses and others will use the IANA standard type of application/json. To ensure consistency with these two content types, this method will always return MIME_CONTENT_TEXT for JSON responses.

Requirements

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

See Also

GetHeader, SetContentType, SetHeader