Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
CURL.SetOptionPost
Sets transfer to be a HTTP Post.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
CURL | 2.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
curl | The CURL session handle. | $curl |
Value | Whether this is a POST request. | 1 |
Result
Returns "OK" on success.
Description
Sets transfer to be a HTTP Post.A parameter set to 1 tells the library to do a regular HTTP post. This will also make the library use a "Content-Type: application/x-www-form-urlencoded" header. (This is by far the most commonly used POST method).
Use one of CURL.SetOptionPostFields options to specify what data to post.
Optionally, you can provide data to POST using the CURL.SetInput* functions but then you must make sure to not set CURL.SetOptionPostFields to anything but "". When providing data with a callback, you must transmit it using chunked transfer-encoding. To enable chunked encoding, you simply pass in the appropriate Transfer-Encoding header.
You can override the default POST Content-Type: header by setting your own with CURL.SetOptionHTTPHeader.
Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURL.SetOptionHTTPHeader as usual.
If you use POST to a HTTP 1.1 server, you can send data without knowing the size before starting the POST if you use chunked encoding. You enable this by adding a header like "Transfer-Encoding: chunked" with CURL.SetOptionHTTPHeader. With HTTP 1.0 or without chunked transfer, you must specify the size in the request.
When setting CURL.SetOptionPost to 1, it will automatically set CURL.SetOptionNoBody to 0 (since 7.14.1).
If you issue a POST request and then want to make a HEAD or GET using the same re-used handle, you must explicitly set the new request type using CURL.SetOptionNoBody or CURL.SetOptionGet or similar.
For debugging, the website https://www.posttestserver.com is very useful. It allows you to see what is received on the other end for a post operation.
If you need GET, please use CURL.SetOptionGet. If you need DELETE, PATCH or others, please use CURL.SetOptionCustomRequest function.
See also POST option in CURL manual.
Examples
Enables POST option:
MBS( "CURL.SetOptionPost"; $curl; 1 )
Run a generic POST request for REST or SOAP web service:
# new session
Set Variable [$curl; Value:MBS("CURL.New")]
# use stripe charge API
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "https://someURL/service")]
# set user name and password if needed:
Set Variable [$result; Value:MBS("CURL.SetOptionUserName"; $curl; "user name")]
Set Variable [$result; Value:MBS("CURL.SetOptionPassword"; $curl; "password")]
# set some additional headers, which may include custom authorization and content types:
Set Variable [$result; Value:MBS( "CURL.SetOptionHTTPHeader"; $curl; "Authorization: Bearer a92eabb9-76f9-42ee-b280-bcd15cb2e9db"; "Content-Type: application/json" )]
# make a post with given content:
Set Variable [$result; Value:MBS("CURL.SetOptionPostFields"; $curl; $json )]
# perform
Set Field [CURL Test::Result; MBS("CURL.Perform"; $curl)]
# now check result
Set Field [CURL Test::Text; MBS("CURL.GetResultAsText"; $curl; "UTF8")]
Set Field [CURL Test::header; MBS("CURL.GetDebugMessages"; $curl)]
# cleanup
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Using Rosette web service:
# Start new CURL transfer
Set Variable [$curl; Value:MBS("CURL.New")]
# Set options like Verbose Debug Messages
Set Variable [$result; Value:MBS("CURL.SetOptionVerbose"; $curl; 1)]
# the url of webservice
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "https://api.rosette.com/rest/v1/morphology/parts-of-speech")]
# the header info for tagging, API Key comes from a global field.
Set Variable [$result; Value:MBS("CURL.SetOptionHTTPHeader"; $curl; "user_key: " & RosetteAPISettings::RosetteAPIKey; "Content-Type: application/json"; "Accept: application/json" )]
# We want a POST transfer:
Set Variable [$result; Value:MBS("CURL.SetOptionPost"; $curl; 1 )]
# Build JSON using the plugin function to properly encode a string:
Set Variable [$request; Value:"{\"content\": " & MBS("JSON.CreateString"; TextData::TextAsInput) & "}"]
Set Variable [$result; Value:MBS("CURL.SetOptionPostFields"; $curl; $request)]
#show our JSON in a field for debugging:
Set Field [TextData::CURLInput; $request]
#Run transfer
Set Variable [$result; Value:MBS("CURL.Perform"; $curl)]
# Check result and debug messages
Set Field [TextData::CurlDebug; MBS("CURL.GetDebugMessages"; $curl)]
Set Field [TextData::CurlOutput; MBS("CURL.GetResultAsText"; $curl)]
# Cleanup
Set Variable [$r; Value:MBS("CURL.Release"; $curl)]
Charge with Stripe webservice:
# new session
Set Variable [$curl; Value:MBS("CURL.New")]
# use stripe charge API
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "https://api.stripe.com/v1/charges")]
# set user name
Set Variable [$result; Value:MBS("CURL.SetOptionUserName"; $curl; "sk_test_ your id here")]
# make a post with given content:
Set Variable [$result; Value:MBS("CURL.SetOptionPost"; $curl; 1)]
Set Variable [$result; Value:MBS("CURL.SetOptionPostFields"; $curl; "amount=400¤cy=usd&description=Charge%20for%20test@example.com&source[object]=card&source[number]=4242424242424242&source[exp_month]=12&source[exp_year]=2017&source[cvc]=123")]
# perform
Set Field [CURL Test::Result; MBS("CURL.Perform"; $curl)]
# now check result
Set Field [CURL Test::Text; MBS("CURL.GetResultAsText"; $curl; "UTF8")]
Set Field [CURL Test::header; MBS("CURL.GetDebugMessages"; $curl)]
# cleanup
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
See also
- CURL.SetOptionGet
- CURL.SetOptionPostRedir
- CURL.SetOptionPut
- CURL.SetOptionQuote
- CURL.SetOptionRange
- CURL.SetOptionSSLCert
- CURL.SetOptionSSLKey
- CURL.SetOptionUserName
- CURL.SetOptionVerbose
- JSON.CreateString
Release notes
- Version 10.4
- Fixed an issue with CURL.SetOptionPostFields to accept > 8 MB in size of post data.
Example Databases
- CURL/Amazon S3/Amazon S3 Upload File
- CURL/CURL Send Form
- CURL/WebServices/AdobeSign WebService
- CURL/WebServices/CURL FMS Admin API v18
- CURL/WebServices/Magento2 REST API
- CURL/WebServices/TinyURL
- Third Party/Google OAUTH 2 example
Blog Entries
- Comparing Base Elements Plugin to MBS FileMaker Plugin
- Using CURL with Rosette web service
- Translate PHP script with CURL to FileMaker Script
- CURL from command line to Plugin
FileMaker Magazin
Created 18th August 2014, last changed 3th February 2023