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

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

Parameters

lpszContentType
A string 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. If this parameter is NULL, the content type will not be copied but the method will return the length of the Content-Type header value.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the buffer, including the terminating null. If the lpszContentType parameter is NULL, this value must be zero.

Return Value

If the method succeeds, the return value is the length of the Content-Type header value. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The GetContentType method returns the MIME type reported by the server in the Content-Type response header for the most recent navigation. This value reflects the server's indication of what kind of content is being delivered, such as "text/html", "application/pdf", or "image/png". The returned string is preserved until the next navigation begins, even if the document is cleared or headers are reset.

It is important to note that not all servers will provide a Content-Type header. Some intentionally omit this information in combination with a X-Content-Type-Options: nosniff header as a security measure to prevent the client from "sniffing" or inferring the type. In such cases, GetContentType will return an empty string. Applications should be prepared for this scenario and not assume a value will always be available.

This method is a convenience wrapper around the underlying response header and is useful for distinguishing whether the WebView is rendering standard HTML or other document types. If more detailed information is needed about the response, developers can enumerate the response headers directly using GetFirstHeader and GetNextHeader.

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

See Also