CWebView::GetFirstHeader Method  
 
BOOL GetFirstHeader(
  LPTSTR lpszHeaderName,  
  INT nMaxNameLen,  
  LPTSTR lpszHeaderValue,  
  INT nMaxValueLen  
);

The GetFirstHeader method begins enumerating response headers and returns the first name/value pair.

Parameters

lpszHeaderName
A string buffer which will contain the name of the first header returned by the server. If this parameter is NULL it will be ignored.
nMaxNameLen
An integer which specifies the maximum number of characters which can be copied into the lpszHeaderName string buffer, including the terminating null. If the lpszHeaderName parameter is NULL this value should be zero.
lpszHeaderValue
A string buffer which will contain the value of the first header returned by the server. If this parameter is NULL, it will be ignored.
nMaxValueLen
An integer which specifies the maximum number of characters which can be copied into the lpszHeaderValue string buffer, including the terminating null. If the lpszHeaderValue parameter is NULL this value should be zero.

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

The response headers exposed by this method correspond to the most recent completed navigation for the specified browser instance. Callers typically use this method to start an enumeration and then call GetNextHeader repeatedly until it returns FALSE to indicate there are no more headers to enumerate.

Header names are case-insensitive by definition. This method will usually return header names as lower-case values, but applications should never depend on the casing and should compare names case-insensitively. The header names and values are returned exactly as enumerated internally by the WebView2 control.

Some response headers can appear multiple times in a message. For list-valued headers (those defined by the HTTP specifications to be comma-joinable), the implementation may return a single entry with a comma-separated value (e.g., Accept-Language, Cache-Control, etc.). Other headers must not be combined; for example, each Set-Cookie header is returned as a separate name/value pair and will be seen multiple times during enumeration, each with a single cookie value. Code that depends on specific headers should be prepared for either a single combined value or multiple discrete occurrences of the same header name, depending on the header's semantics.

Enumeration reflects a snapshot of the headers for that response. Beginning a new navigation or calling ClearHeaders invalidates the current enumeration. Only one header enumeration can be active per browser instance at a time. The enumeration state is not thread-safe, and any access to the response headers should be synchronized across different threads.

If the provided buffers are too small, the header names and values will be truncated to the available space specified by the maximum length parameters. In most cases, a header name is not going to exceed 256 characters and a header value will normally not exceed 5120 characters. Most header values are relatively short, but some headers such as Set-Cookie can return much longer values.

This method cannot be called while the browser is in the process of navigating to a new location. It will also fail if the current document is a local file or if the document text was set dynamically using SetDocumentText. There are no response headers available in a local context.

Example

TCHAR szName[WEBVIEW_MAX_HEADER_NAME];
TCHAR szValue[WEBVIEW_MAX_HEADER_VALUE];

if (pWebView->GetFirstHeader(szName, _countof(szName),
                             szValue, _countof(szValue)))
{
    do
    {
        _tprintf(_T("%s: %s\n"), szName, szValue);
    }
    while (pWebView->GetNextHeader(szName, _countof(szName),
                                   szValue, _countof(szValue)));
}
else
{
    DWORD dwError = pWebView->GetLastError();
    _tprintf(_T("No headers available (error 0x%lx)\n"), dwError);
}

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