SetHttpRequestHeader

Description

Sets the HTTP request header.

Applies to

Application object

Syntax

applicationname.SetHttpRequestHeader ( string headerName, string headerValue{, Boolean replace } )

Argument

Description

applicationname

The name of the application 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 1) TRUE is recommended when you specify the charset in the "Content-Type" header, because no more than one charset is allowed; 2) FALSE is recommended when cookie is used.


Return value

Integer.

Returns 1 if it succeeds and -1 if an error occurs or if the current application is not an installable cloud app deployed with PowerServer. If any argument's value is null, the method returns null.

Examples

The following code example sets the access token in the HTTP request header:

Long ll_Return
String ls_TokenType, ls_AccessToken, ls_Json
JsonParser ljson_Parser

ljson_Parser = Create JsonParser

ls_Json = '{' +&
'    "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjM4OEQ0NEIxRDdBNkVFOUQxNTU0MDAzQUMzM0QzQzkzIiwidHlwIjoiYXQrand0In0.eyJuYmYiOjE2MTI0MDIxODUsImV4cCI6MTYxMjQwMjM2NSwiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NTAwMSIsImNsaWVudF9pZCI6IllvdXJDbGllbnRJZFRoYXRDYW5Pbmx5UmVhZCIsInN1YiI6IlBBTkdDSFVHVUFOIiwiYXV0aF90aW1lIjoxNjEyNDAyMTg1LCJpZHAiOiJsb2NhbCIsImp0aSI6IjFDNEQ4NEFBODU0REYxODMwQkVGQTAwQTFBMjdFMDk0IiwiaWF0IjoxNjEyNDAyMTg1LCJzY29wZSI6WyJzY29wZS5yZWFkYWNjZXNzIl0sImFtciI6WyJjdXN0b20iXX0.DbJsip696O1HlTFjAmayohhHGEcjIQxJM7JICi9ho5MAv2Av4YjQOGgXrCNFhwqG4AFTf3hHwufGYXxzXI8tCYfn3F3ro36dd-0h_A-__5sBelZD0vr6nmWh8Uy-zoJenzsrnVEv8VHVNi2enuKH6SBe-Q59bn5A-Gbg6viNjv0S5HIaKuWeawExBH6uEAu28RlSlfG2bwWuCsyhYWOPIhNhYcZTbVD8ks0SFodGeGS-ZqNOVrOTKb9oqnhvYxnuNofJpjToZ8ZZdKyWiyJUhItpTQTyI3MsCHoVU4X101YTPrVMF_-OuPSwXm6QMl3QtI_6Hy_PeYHL-xz2-q3tog",' +&
'    "expires_in": 3600,' +&
'    "token_type": "Bearer",' +&
'    "scope": "scope.readaccess"' +&
'}'

ljson_Parser.LoadString( ls_Json )
ls_TokenType = ljson_Parser.GetItemString( "/token_type" )
ls_AccessToken = ljson_Parser.GetItemString( "/access_token" )

ll_Return = Getapplication().SetHttpRequestHeader( "Authorization", ls_TokenType + " " + ls_AccessToken, True )

If IsValid ( ljson_Parser ) Then Destroy ( ljson_Parser )

The following code example sets the cookie in the HTTP request header:

Notice that you can only set the cookie name and cookie value in the key-value pairs (for example, "key1=value1; key2=value2"), and cannot set the other properties such as Domain, Expires etc.

GetApplication().SetHttpRequestHeader ("cookie", "appcookie=test_cookie;PSTM=1634527936;")

See also

BeginSession

GetHttpResponseHeaders

GetHttpResponseStatusCode

GetHttpResponseStatusText