Help Center

CWinHttpRequest.SetRequestHeadermethod

Adds, changes, or deletes an HTTP request header.

COMmethoddocumented

Syntax

FUNCTION SetRequestHeader (BYREF wszHeader AS WSTRING, BYREF wszValue AS WSTRING) AS HRESULT

Parameters

NameDescription
wszHeaderA value of type CBSTR that specifies the name of the header to be set, for example, "depth". This parameter should not contain a colon and must be the actual text of the HTTP header.
wszValueAn string that specifies the value of the header, for example, "infinity".

Description

Adds, changes, or deletes an HTTP request header.

Return value

Returns S_OK if successful or an error value otherwise.

Remarks

Headers are transferred across redirects. This can create a security vulnerability. To avoid having headers transferred if a redirect occurs, use the WINHTTP_STATUS_CALLBACK callback to correct the specific headers when a redirect occurs.

The SetRequestHeader method enables the calling application to add or delete an HTTP request header prior to sending the request. The header name is given in wszHeader, and the header token or value is given in wszValue. To add a header, supply a header name and value. If another header already exists with this name, it is replaced. To delete a header, set cbsHeader to the name of the header to delete and set cbsValue to NULL.

The name and value of request headers added with this method are validated. Headers must be well formed. For more information about valid HTTP headers, see RFC 2616. If an invalid header is used, an error occurs and the header is not added.

Reference

  • Defined in AfxNova/CWinHttpRequest.inc:425
  • Documented in COM/CWinHttpRequest Class.md
  • Topic: CWinHttpRequest Class