SetRequestHeader

Description

Sets the request header.

Applies to

HTTPClient and RestClient objects

Syntax

objectname.SetRequestHeader ( string headerName, string headerValue{, Boolean replace } )

Argument

Description

objectname

The name of the HTTPClient or RestClient object in which you want to set the request header.

headerName

A string whose value is the header name.

headerValue

A string whose value is the header value.

replace (optional)

A boolean determines whether to replace the current existing request value if the same header name already exists.

  • TRUE -- to replace the value in the current existing request header if the same header name already exists.

  • FALSE -- to add the value (with a “,”) to the current existing request header if the same header name already exists. The default value is FALSE.

Note: use this argument cautiously (TRUE is recommended) when you specify the charset in the "Content-Type" header, because no more than one charset is allowed.


Return value

Long.

Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is null, the method returns null.

Examples

This example constructs a GET request which supports all header settings:

HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient
lnv_HttpClient.SetRequestHeader("Accept", "*/*")
lnv_HttpClient.SetRequestHeader("Accept-Encoding", "gzip")
lnv_HttpClient.SetRequestHeader("Accept-Language", "en")
lnv_HttpClient.SetRequestHeader("Connection", "keep-alive")
lnv_HttpClient.SetRequestHeader("User-Agent", "Chrome/60.0.3112.113")
lnv_HttpClient.SetRequestHeader("Cache-Control", "no-cache")

See also

ClearRequestHeaders

GetRequestHeader

GetRequestHeaders

SetRequestHeaders