Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

CURL.SetOptionHTTPHeader

Sets the http header list.

Component Version macOS Windows Linux Server iOS SDK
CURL 2.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "CURL.SetOptionHTTPHeader"; curl; Values... )   More

Parameters

Parameter Description Example
curl The CURL session handle. $curl
Values... Header values "Content-Type: text/xml"

Result

Returns "OK" on success.

Description

Sets the http header list.
Pass a list of HTTP headers to pass to the server in your HTTP request. If you add a header that is otherwise generated and used by libcurl internally, your added one will be used instead. If you add a header with no content as in 'Accept:' (no data on the right side of the colon), the internally used header will get disabled. Thus, using this option you can add new headers, replace internal headers and remove internal headers. To add a header with no content, make the content be two quotes: "". The headers included in the linked list must not be CRLF-terminated, because curl adds CRLF after each header item. Failure to comply with this will result in strange bugs because the server will most likely ignore part of the headers you specified.

The first line in a request (containing the method, usually a GET or POST) is not a header and cannot be replaced using this option. Only the lines following the request-line are headers. Adding this method line in this list of headers will only cause your request to send an invalid header.

Pass a no parameters to this to reset back to no custom headers.

The most commonly replaced headers have "shortcuts" in the options CURL.SetOptionCookie, CURL.SetOptionUserAgent and CURL.SetOptionReferer.

This option takes a list of items. So this function takes a variable number of arguments. If you call function with 2 parameters, you set an empty list. If you call it with 5 parameters, you set a list with 3 values.

Do not pass special headers like Content-Length as this is set based on the given input via CURL.SetOptionPostFields. Do not set Content-Encoding as that is controlled by CURL.SetOptionAcceptEncoding.

This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.
Please repeat Values parameter as often as you need.

See also HTTPHEADER option in CURL manual.

Examples

Set text/xml content type:

MBS( "CURL.SetOptionHTTPHeader"; $curl; "Content-Type: text/xml" )

Set two custom headers:

MBS( "CURL.SetOptionHTTPHeader"; $curl; "MyHeader1: hello"; "MyHeader2: world" )

Call with three parameters:

MBS( "CURL.SetOptionHTTPHeader"; handle; $value1; $value2; $value3 )

For SOAP, set content type and disable Expect header:

MBS("CURL.SetOptionHTTPHeader"; $curl; "Expect:"; "Content-Type: text/xml")

Set content type including a soap action:

MBS( "CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/soap+xml;charset=UTF-8;action=\"urn:sap-com:document:sap:soap:functions:mc-style:ZMF_WS_00:ZmfWs00Request\"" )

Request no cached copy:

MBS("CURL.SetOptionHTTPHeader"; $curl; "Cache-Control: no-cache")

Set content type for URL encoded form data:

MBS( "CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/x-www-form-urlencoded" )

Using a bearer for a webservice:

MBS( "CURL.SetOptionHTTPHeader"; $curl; "Authorization: Bearer a92eabb9-76f9-42ee-b280-bcd15cb2e9db"; "Content-Type: application/json")

Set SOAP Action and Content-Type for webservice:

MBS("CURL.SetOptionHTTPHeader"; $curl;
"Content-Type: text/xml;charset=\"utf-8\"";
"SOAPAction: \"" & $SoapRequestName &"\"")

Query current account for Dropbox:

# Start new session
Set Variable [ $curl ; Value: MBS("CURL.New") ]
# Set URL to load (HTTP, HTTPS, FTP, FTPS, SFTP, etc.)
Set Variable [ $result ; Value: MBS("CURL.SetOptionURL"; $curl; "https://api.dropboxapi.com/2/users/get_current_account") ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionCustomRequest"; $curl; "POST") ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Accept: */*"; "Authorization: Bearer xxx"; "Cache-Control: no-cache"; "accept-encoding: gzip, deflate"; "cache-control: no-cache"; "content-length:") ]
# RUN now
Set Field [ CURL Test::Result ; MBS("CURL.Perform"; $curl) ]
# Check result
Set Field [ CURL Test::Text ; MBS("CURL.GetResultAsText"; $curl; "UTF8") ]
Set Field [ CURL Test::debug ; MBS("CURL.GetDebugMessages"; $curl) ]
# Cleanup
Set Variable [ $result ; Value: MBS("CURL.Release"; $curl) ]

OAuth2 Token authentication with passing credentials via POST:

Set Variable [ $Curl ; Value: MBS("CURL.New") ]
#
# Change path to your CACert PEM File.
Set Variable [ $CacertPath ; Value: "C:\Users\Public\cacert.pem" ]
// Set Variable [ $Result ; Value: MBS( "CURL.SetOptionCAInfo"; $curl; $cacertPath ) ]
// Set Variable [ $Result ; Value: MBS( "CURL.SetOptionSSLVerifyHost"; $curl; 2 ) ]
// Set Variable [ $Result ; Value: MBS( "CURL.SetOptionSSLVerifyPeer"; $curl; 1 ) ]
Set Variable [ $Result ; Value: MBS("CURL.SetOptionVerbose"; $curl; 1) ]
#
# credentials
Set Variable [ $secret ; Value: "xxx" ]
Set Variable [ $client ; Value: "yyy" ]
Set Variable [ $domain ; Value: "zzz" ]
Set Variable [ $Result ; Value: MBS("CURL.SetOptionURL"; $curl; "https://" & $domain & "/auth/realms/demo/protocol/openid-connect/token") ]
#
# POST with form encoding
Set Variable [ $result ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "content-type: application/x-www-form-urlencoded") ]
Set Variable [ $Result ; Value: MBS("CURL.SetOptionPostFields"; $curl; "grant_type=client_credentials&client_id="& $client & "&client_secret=" & $secret) ]
#
# run it
Set Variable [ $Result ; Value: MBS("CURL.Perform"; $curl) ]
Set Variable [ $DebugText ; Value: MBS("CURL.GetDebugMessages"; $curl) ]
Set Variable [ $ResultText ; Value: MBS("CURL.GetResultAsText"; $curl) ]
If [ $result = "OK" ]
    # extract token
    Set Variable [ $Token ; Value: JSONGetElement ( $ResultText; "access_token" ) ]
    Set Field [ tbl_debugger::token ; $Token ]
End If
Set Field [ tbl_debugger::header ; $DebugText ]
Set Variable [ $Result ; Value: MBS("CURL.Release"; $curl) ]

See also

Release notes

Example Databases

Blog Entries

Created 18th August 2014, last changed 22nd June 2021


CURL.SetOptionHTTPContentDecoding - CURL.SetOptionHTTPProxyTunnel