共用方式為


HttpAddRequestHeaders

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function adds one or more Hypertext Transfer Protocol (HTTP) request headers to the HTTP request handle.

Syntax

BOOL WINAPI HttpAddRequestHeaders(
  HINTERNET hHttpRequest, 
  LPCTSTR lpszHeaders, 
  DWORD dwHeadersLength, 
  DWORD dwModifiers
);

Parameters

  • lpszHeaders
    [in] Long pointer to the null-terminated strings that contains headers to append to the request. Each header must be terminated by a CR/LF (carriage return/line feed) pair.
  • dwHeadersLength
    [in] Specifies the length, in characters, of lpszHeaders. If this parameter is -1L, the function assumes that lpszHeaders is zero-terminated (ASCIIZ), and the length is computed. The length of header must not include the null terminator at the end of the string. If the null character is included, the headers will not be parsed correctly.
  • dwModifiers
    [in] Specifies the values used to modify the semantics of this function. The following table shows the possible values for this parameter. The values can be used in any combination.

    Value Description

    HTTP_ADDREQ_FLAG_ADD

    Adds the header if it does not exist. Used with HTTP_ADDREQ_FLAG_REPLACE.

    HTTP_ADDREQ_FLAG_ADD_IF_NEW

    Adds the header only if it does not already exist; otherwise, an error is returned.

    HTTP_ADDREQ_FLAG_COALESCE

    Coalesces headers of the same name.

    HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA

    Coalesces headers of the same name. For example, adding "Accept: text/*" followed by "Accept: audio/*" with this flag results in the formation of the single header "Accept: text/*, audio/*". This causes the first header found to be coalesced. It is up to the calling application to ensure a cohesive scheme with respect to coalesced/separate headers.

    HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON

    Coalesces headers of the same name using a semicolon.

    HTTP_ADDREQ_FLAG_REPLACE

    Replaces or removes a header. If the header value is empty and the header is found, it is removed. If not empty, the header value is replaced.

Return Value

TRUE indicates success. FALSE indicates failure. To get extended error information, call GetLastError.

Remarks

This function appends additional, free-format headers to the HTTP request handle and is intended for use by sophisticated clients that need detailed control over the exact request sent to the HTTP server.

If you are calling this function to remove or replace headers, you can pass in only one header at a time to lpszHeaders. You will need to call this function once for every header to be removed or changed. However if you are adding headers, you can pass in multiple headers in a single call.

Requirements

Header wininet.h
Library wininet.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

HttpOpenRequest
HttpSendRequest
WinInet Functions